【发布时间】:2015-11-25 08:28:24
【问题描述】:
我的文本视图对齐有问题。我想将列表视图项的两个文本视图左右对齐。在 Android Studio 编辑器中没问题,但是当我将应用程序部署到设备时,它没有正确对齐。我不知道是什么问题。下面是我的布局:
发现问题。问题实际上出在 listview 上,我错误地设置了 Listview 的 layout_width="wrap_content" 但应该是 match_parent。正如提到的布局是列表的项目布局。谢谢大家。
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="@dimen/activity_horizontal_margin"
android:orientation="vertical">
<TextView
android:id="@+id/tv_order_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"/>
<TextView
android:id="@+id/tv_order_category_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"/>
<TextView
android:id="@+id/tv_order_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="35sp"/>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="10dp"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="@string/order_tin_ein"
android:gravity="left"
android:layout_weight="1"
android:textStyle="bold"/>
<TextView
android:id="@+id/tv_order_tin_ein"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="right"
android:layout_weight="1"
android:text="Test"/>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal">
<TextView
android:layout_width="0dip"
android:layout_height="wrap_content"
android:text="@string/order_address"
android:layout_weight="1"
android:textStyle="bold"/>
<TextView
android:id="@+id/tv_order_address"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right"/>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="@string/order_email"
android:gravity="left"
android:layout_weight="1"
android:textStyle="bold"/>
<TextView
android:id="@+id/tv_order_email"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right"/>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="@string/order_phone"
android:gravity="left"
android:layout_weight="1"
android:textStyle="bold"/>
<TextView
android:id="@+id/tv_order_phone"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right"/>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="@string/order_mobile"
android:gravity="left"
android:layout_weight="1"
android:textStyle="bold"/>
<TextView
android:id="@+id/tv_order_mobile"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right"/>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="@string/order_fax"
android:gravity="left"
android:layout_weight="1"
android:textStyle="bold"/>
<TextView
android:id="@+id/tv_order_fax"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right"/>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="@string/order_created_date"
android:gravity="left"
android:layout_weight="1"
android:textStyle="bold"/>
<TextView
android:id="@+id/tv_order_created_date"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right"/>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="@string/order_start_working_date"
android:gravity="left"
android:layout_weight="1"
android:textStyle="bold"/>
<TextView
android:id="@+id/tv_order_start_working_date"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right"/>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="@string/order_end_date"
android:gravity="left"
android:layout_weight="1"
android:textStyle="bold"/>
<TextView
android:id="@+id/tv_order_end_date"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right"/>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="@string/order_cost"
android:gravity="left"
android:layout_weight="1"
android:textStyle="bold"/>
<TextView
android:id="@+id/tv_order_cost"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right"/>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="@string/order_vat"
android:gravity="left"
android:layout_weight="1"
android:textStyle="bold"/>
<TextView
android:id="@+id/tv_order_vat"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right"/>
</TableRow>
</TableLayout>
【问题讨论】:
-
你的代码没问题。当我们部署在我的设备中时。
-
在我的设备上很奇怪,android 6.0 不行
-
在设备中显示文本的位置
-
第一个文本视图附近
-
你在片段中使用它们吗?
标签: android