【发布时间】:2012-07-24 18:42:22
【问题描述】:
如何正确对齐产品名称和产品等级。我从 db 中检索产品名称,因为名称太长对齐不在同一位置。请帮忙谢谢
<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tableLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:shrinkColumns="*"
android:stretchColumns="*" >
<TableRow
android:id="@+id/tableRow3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/birdnesttoppanel"
android:gravity="center_horizontal" >
<TextView
android:id="@+id/textView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:textStyle="bold"
android:typeface="serif" >
</TextView>
</TableRow>
<TableRow
android:id="@+id/tableRow4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal" >
<LinearLayout
android:layout_span="6"
android:gravity="center" >
<ImageButton
android:id="@+id/preview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_gravity="center"
android:background="@drawable/newclick"
android:text="Click here to view the picture" />
</LinearLayout>
</TableRow>
<TableRow
android:id="@+id/tableRow5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:textSize="18dp"
android:textStyle="bold"
android:typeface="serif" >
</TextView>
</TableRow>
<TableRow
android:id="@+id/tableRow6new"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal" >
<LinearLayout
android:layout_span="6"
android:gravity="center" >
<TextView
android:id="@+id/ProductName1"
android:text="@string/ProductName"
android:textStyle="bold"
android:typeface="serif"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</TextView>
<TextView
android:id="@+id/ProductName2"
android:text=":"
android:textStyle="bold"
android:typeface="serif"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</TextView>
<TextView
android:id="@+id/ProductName3"
android:text=""
android:textStyle="bold"
android:typeface="serif"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</TextView>
</LinearLayout>
</TableRow>
<TableRow>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_span="6"
android:gravity="center"
android:textSize="2dp"
android:textStyle="bold"
android:typeface="serif" >
</TextView>
</TableRow>
<TableRow
android:id="@+id/tableRow6new1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal" >
<LinearLayout
android:layout_span="6"
android:gravity="center" >
<TextView
android:id="@+id/ProductGrade1"
android:text="@string/ProductGrade"
android:textStyle="bold"
android:typeface="serif"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
</TextView>
<TextView
android:id="@+id/ProductGrade2"
android:text=":"
android:textStyle="bold"
android:typeface="serif"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
</TextView>
<TextView
android:id="@+id/ProductGrade3"
android:text=""
android:textStyle="bold"
android:typeface="serif"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
</TextView>
</LinearLayout>
</TableRow>
【问题讨论】:
-
术语“正确对齐”可以有多种解释。更具体一些,例如:将两个标签左对齐、右对齐、一个在另一个之上...
-
@AndyRes。感谢您的评论。如果您看到我的屏幕截图,您可以看到产品名称和产品等级在不同的位置。我希望两者都向左对齐。
标签: android alignment android-linearlayout android-tablelayout