title: TextView android:gravity set to center_horizontal not working correctly when drawn to a bitmap
body: <p>IMPORTANT:
  I want to draw content of a View A to a bitmap and part of the View A is a TextView which text has to be centered horizontally. The View A is not displayed nor is part of another View.</p>
  
  <p>QUESTION:
  How can I tell the TextView to display the text correctly when it is drawn to a bitmap????</p>
  
  <p>My base layout(base_layout.xml):</p>
  
  <pre><code>&lt;LinearLayout
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:orientation="horizontal"
      android:baselineAligned="false" &gt;
  
      &lt;TextView
          android:id="@+id/dateTV"
          android:layout_width="0dp"
          android:layout_height="wrap_content"
          android:layout_weight="1"
          android:layout_marginRight="5dp"
          android:gravity="center"
          android:padding="3dp"
          android:textStyle="bold" /&gt;
  
      &lt;TextView
          android:id="@+id/shiftsListTV"
          android:layout_width="0dp"
          android:layout_height="wrap_content"
          android:layout_weight="1"
          android:gravity="center"
          android:singleLine="false"
          android:maxLines="2"
          android:padding="3dp" /&gt;
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>My TestActivity.java activity, which I use for testing:</p>
  
  <pre><code>public class TestActivity extends Activity {
  
      private LinearLayout mainHolderLL;
  
      @Override
      protected int getLayoutXml() {
          return R.layout.activity_test;
      }
  
      @Override
      protected final void onCreate(Bundle savedInstanceState) {
          mainHolderLL = (LinearLayout) findViewById(R.id.mainHolderLL);
  
          View baseLayoutView = View.inflate(context, R.layout.base_layout, null);
  
                  dateTV.setText("Feb 2014");
                  shiftsListTV.setText("shift1, shift2");
          int width = 500;
          int height = 500;
  
          int widthMeasureSpec = MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY);
          int heightMeasureSpec = MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY);
  
          baseLayoutView.measure(widthMeasureSpec, heightMeasureSpec);        
          baseLayoutView.layout(0, 0, baseLayoutView.getMeasuredWidth(), baseLayoutView.getMeasuredHeight());
  
                  Bitmap bitmap = Bitmap.createBitmap(baseLayoutView.getMeasuredWidth(),                                  baseLayoutView.getMeasuredHeight(), Bitmap.Config.ARGB_8888);       
                  Canvas canvas = new Canvas(bitmap);     
                  baseLayoutView.draw(canvas);
  
                  ImageView appwidget_image_view = (ImageView) findViewById(R.id.appwidget_image_view);       
          appwidget_image_view.setImageBitmap(bitmap);
      }
  }
  </code></pre>
  
  <p>activity_test.xml:</p>
  
  
  
  <pre><code>&lt;HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="match_parent"
      android:layout_height="match_parent" &gt;
  
      &lt;ScrollView
          android:layout_width="match_parent"
          android:layout_height="match_parent" &gt;
  
          &lt;LinearLayout
              android:id="@+id/mainHolderLL"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:orientation="vertical"
              android:padding="@dimen/common_padding_normal" &gt;
  
              &lt;ImageView
                  android:id="@+id/appwidget_image_view"
                  android:layout_width="294dp"
                  android:layout_height="294dp"
                  android:background="@android:color/black"
                  android:cropToPadding="false"
                  android:padding="@dimen/widget_margin"
                  android:scaleType="fitXY"
                  tools:ignore="ContentDescription" /&gt;
          &lt;/LinearLayout&gt;
      &lt;/ScrollView&gt;
  
  &lt;/HorizontalScrollView&gt;
  </code></pre>
  
  <p>If the bitmap is displayed inside a ImageView, the text inside dateTV TextView is not centered horizontally and it looks as crushed(on Android 4.3 but on Android 2.3.3 nothing is displayed), but the text inside shiftsListTV is displayed correctly.</p>
  
  <p>If I remove the <code>android:gravity</code> attribute from dateTv TextView the text inside dateTV is displayed correctly but is not centered. I need the text centered.</p>
  
  <p>Edit:</p>
  
  <p>After some research I found out that TextView has a problem with gravity tag.</p>
  
  <p>The imageview is NOT important it is solely for displaying the bitmap.</p>