我有4个TextView的GridView,我正在使用SimpleAdapter来处理它。 这是TextView的xml代码:
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/background_light"
android:gravity="top"
android:textAlignment="gravity"
android:textSize="12sp"
但是当我尝试将文本设置为其中一个TextView时,对齐方式无法正常工作:
即。 TextView中的文本位置取决于GridView行中的TextView索引。 那么这种奇怪行为的原因是什么?
UPD: 这是活动布局代码:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".WordMakerGameActivity" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/textView1"
android:layout_width="85dp"
android:layout_height="match_parent"
android:gravity="center"
android:text="@string/pult"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/textView2"
android:layout_width="83dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:gravity="center"
android:text="@string/pult_image"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/textView3"
android:layout_width="99dp"
android:layout_height="match_parent"
android:gravity="center"
android:text="@string/last_letters_readed"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/textView4"
android:layout_width="108dp"
android:layout_height="match_parent"
android:gravity="center"
android:text="@string/words_composed"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/textView5"
android:layout_width="129dp"
android:layout_height="match_parent"
android:gravity="center"
android:text="@string/wrong_words_composed"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/textView6"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="@string/points"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
<GridView
android:id="@+id/wordMakerGameGridView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:numColumns="6"
android:textAlignment="viewStart" >
</GridView>
<Button
android:id="@+id/btnStopWordMakerGame"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@drawable/button_red"
android:onClick="onStopWordMakerGame"
android:text="@string/stop_game"
android:textColor="@android:color/white"
android:textSize="30sp" />
这是我在我的适配器中使用的布局代码:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="2dp"
android:layout_margin="2dip"
android:layout_gravity="center">
<ImageView
android:id="@+id/image_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/background_light"
android:adjustViewBounds="true"/>
<TextView
android:id="@+id/grid_text_view1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/background_light"
android:gravity="top"
android:textSize="12sp" />
<TextView
android:id="@+id/grid_text_view2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/background_light"
android:gravity="top"
android:textSize="12sp" />
<TextView
android:id="@+id/grid_text_view3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/background_light"
android:gravity="top"
android:textSize="12sp" />
<TextView
android:id="@+id/grid_text_view4"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/background_light"
android:gravity="top"
android:textSize="12sp" />
<TextView
android:id="@+id/grid_text_view5"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/background_light"
android:gravity="top"
android:textSize="12sp" />
</LinearLayout>