我有一个ListView
,有10列和一个标题。如下图所示,行未与标题对齐。
如果TextViews中的文本居中,似乎问题会解决。 我尝试过很多东西,但都没有。
*注意:请不要告诉我使用TableLayout
。我已经做到了,但加载速度要慢得多。
这是ListView的xml:
<ListView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@id/LinearLayout1"
android:background="#d9d9d9" >
</ListView>
这是list_header xml:
<TableRow xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/TableRow1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/header_back"
android:orientation="horizontal" >
<TextView
android:id="@+id/stockNumTxt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_weight="1"
android:text="@string/stockNum"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="16sp" />
<TextView
android:id="@+id/shapeTxt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_weight="1"
android:text="@string/shape"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="16sp" />
<TextView
android:id="@+id/weightTxt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_weight="1"
android:text="@string/weight"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="16sp" />
<TextView
android:id="@+id/colorTxt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_weight="1"
android:text="@string/color"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="16sp" />
<TextView
android:id="@+id/clarityTxt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_weight="1"
android:text="@string/clarity"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="16sp" />
<TextView
android:id="@+id/cutGradeTxt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_weight="1"
android:text="@string/cutGrade"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="16sp" />
<TextView
android:id="@+id/labTxt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_weight="1"
android:text="@string/labb"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="16sp" />
<TextView
android:id="@+id/priceTxt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_weight="1"
android:text="@string/price"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="16sp" />
<TextView
android:id="@+id/discountTxt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_weight="1"
android:text="@string/disc"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="16sp" />
<TextView
android:id="@+id/statusTxt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:text="@string/status"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="16sp" />
</TableRow>
这是list_item xml:
<TableRow xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/TableRow1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/list_item_selector"
android:clickable="true"
android:orientation="horizontal" >
<TextView
android:id="@+id/stockNumTxt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="4dp"
android:layout_marginTop="4dp"
android:layout_weight="1"
android:text="@string/stockNum"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@android:color/black"
android:textSize="14sp" />
<TextView
android:id="@+id/shapeTxt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="4dp"
android:layout_marginTop="4dp"
android:layout_weight="1"
android:text="@string/shape"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@android:color/black"
android:textSize="14sp" />
<TextView
android:id="@+id/weightTxt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="4dp"
android:layout_marginTop="4dp"
android:layout_weight="1"
android:text="@string/weight"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@android:color/black"
android:textSize="14sp" />
<TextView
android:id="@+id/colorTxt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="4dp"
android:layout_marginTop="4dp"
android:layout_weight="1"
android:text="@string/color"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@android:color/black"
android:textSize="14sp" />
<TextView
android:id="@+id/clarityTxt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="4dp"
android:layout_marginTop="4dp"
android:layout_weight="1"
android:text="@string/clarity"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@android:color/black"
android:textSize="14sp" />
<TextView
android:id="@+id/cutGradeTxt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="4dp"
android:layout_marginTop="4dp"
android:layout_weight="1"
android:text="@string/cutGrade"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@android:color/black"
android:textSize="14sp" />
<TextView
android:id="@+id/labTxt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="4dp"
android:layout_marginTop="4dp"
android:layout_weight="1"
android:text="@string/lab"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@android:color/black"
android:textSize="14sp" />
<TextView
android:id="@+id/priceTxt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="4dp"
android:layout_marginTop="4dp"
android:layout_weight="1"
android:text="@string/price"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@android:color/black"
android:textSize="14sp" />
<TextView
android:id="@+id/discountTxt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="4dp"
android:layout_marginTop="4dp"
android:layout_weight="1"
android:text="@string/disc"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@android:color/black"
android:textSize="14sp" />
<TextView
android:id="@+id/statusTxt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="4dp"
android:layout_marginTop="4dp"
android:layout_weight="1"
android:text="@string/status"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@color/red"
android:textSize="14sp" />
</TableRow>
谢谢!
答案 0 :(得分:0)
为标题和项目设置相同的文本化 - 您为项目设置ddi 14sp,为标题设置16sp,并且还从项目中删除边距,如果问题仍然保持相同,则将边距/填充放入列表项目