0

Setting gravity on a textView doesn't work on my Galaxy 2, 2.3.3 but does work on my Galaxy Note, 2.3.6. Does anyone have an idea why?
The TextView xml definitions:

<LinearLayout
    android:screenOrientation="portrait"
    android:background="@drawable/w_5"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent" android:layout_height="fill_parent"
    android:layout_gravity="center_horizontal" android:gravity="center_horizontal"
    android:orientation="vertical">

    <TextView android:id="@+id/activities"
        android:layout_width="fill_parent" android:layout_height="wrap_content"
        android:layout_weight="1"
        android:freezesText="true"
        android:textSize="20dip"
        android:scrollbars="vertical"
        android:layout_marginTop="15dp"
        android:layout_marginLeft="15dp"
        android:layout_marginBottom="15dp"
        android:layout_marginRight="15dp" >
        <requestFocus />
    </TextView>
    <Button android:id="@+id/takeAPicture" 
        style="@style/ActionButton"
        android:text="@string/takeAPicture"
        android:background="@drawable/custom_button" />  
    <Button android:id="@+id/googleMaps" 
        style="@style/ActionButton"
        android:text="@string/googleMaps"
        android:background="@drawable/custom_button"  />
    <Button android:id="@+id/navigateThere" 
        style="@style/ActionButton"
        android:text="@string/navigateThere"
        android:background="@drawable/custom_button"  />
</LinearLayout>

Then, setting gravity from Java:

mActivitiesText = (TextView) findViewById(R.id.activities);
mActivitiesText.setGravity(Gravity.RIGHT);

Thanks!!!

n00b programmer
  • 2,671
  • 7
  • 41
  • 56

2 Answers2

0

As seen in the reference page: http://developer.android.com/reference/android/view/Gravity.html gravity is added in API lvl 1, it means that all android Devices supports this property, anywway, you can add it into the XML, there:

<TextView android:id="@+id/activities"
        android:layout_width="fill_parent" android:layout_height="wrap_content"
        android:layout_weight="1"
        android:freezesText="true"
        android:textSize="20dip"
        android:scrollbars="vertical"
        android:layout_marginTop="15dp"
        android:layout_marginLeft="15dp"
        android:layout_marginBottom="15dp"
        android:layout_marginRight="15dp" 
        android:gravity="right">
        <requestFocus />
    </TextView>
Leonardo Sapuy
  • 2,600
  • 2
  • 23
  • 30
0

Why not try

<TextView android:id="@+id/activities"
    ...
    android:gravity="right" >
    ...
</TextView>

What is your desired effect here? You're setting layout_width="fill_parent" on your TextView, so that could be part of the problem.

Jon Willis
  • 6,993
  • 4
  • 43
  • 51