我有以下的代码,这是我有一个列表视图的行布局。我希望标签位于左侧,数据位于右侧。数据应该在左侧对齐,但目前看起来是歪斜的。LinearLayout对齐Textviews使用重量参数
我曾尝试在linearlayout中为文字指定权重。该标签的权重为1,数据的权重为5.我预计数据文字视图会垂直排列,因为它们应该占据水平宽度的5/6,只剩下标签的1/6。
为什么数据TextViews不是同样占用了屏幕宽度的一样多吗?
在开发人员选项我检查了展会的布局界限,它证明了数据textviews不垂直对齐。
<?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:background="@color/white"
android:paddingTop="10dp"
android:paddingBottom="10dp">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:id="@+id/carerinfotypelabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Type: "
android:layout_weight="1"
android:textColor="@color/cf_blue"
/>
<TextView
android:id="@+id/carerinfotype"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="5"
/>
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:id="@+id/carerinfosurnamelabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Name: "
android:layout_weight="1"
android:textColor="@color/cf_blue"
/>
<TextView
android:id="@+id/carerinfosurname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="5"
android:layout_below="@id/carerinfotypelabel"
/>
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:id="@+id/carerinfoaddresslabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Address: "
android:layout_weight="1"
android:textColor="@color/cf_blue"
/>
<TextView
android:id="@+id/carerinfoaddress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="5" />
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:id="@+id/carerinfopostcodelabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Postcode: "
android:layout_weight="1"
android:textColor="@color/cf_blue"
/>
<TextView
android:id="@+id/carerinfopostcode"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="5" />
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:id="@+id/carerinfomobilelabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Mobile: "
android:layout_weight="1"
android:textColor="@color/cf_blue"
/>
<TextView
android:id="@+id/carerinfomobile"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="5"
/>
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:id="@+id/carerinfotelhomelabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Home Tel: "
android:layout_weight="1"
android:textColor="@color/cf_blue"
/>
<TextView
android:id="@+id/carerinfotelhome"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="5"
/>
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:id="@+id/carerinfotelno1label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tel 1: "
android:layout_weight="1"
android:textColor="@color/cf_blue"
/>
<TextView
android:id="@+id/carerinfotelno1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="5" />
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:id="@+id/carerinfotel2label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tel 2: "
android:layout_weight="1"
android:textColor="@color/cf_blue"
/>
<TextView
android:id="@+id/carerinfotel2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="5"
/>
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:id="@+id/carerinfotel3label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tel 3: "
android:layout_weight="1"
android:textColor="@color/cf_blue"/>
<TextView
android:id="@+id/carerinfotel3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="5"/>
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:id="@+id/carerinfotel4label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tel 4: "
android:layout_weight="1"
android:textColor="@color/cf_blue"/>
<TextView
android:id="@+id/carerinfotel4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="5" />
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:id="@+id/carerinforelationshiplabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Relationship: "
android:layout_weight="1"
android:textColor="@color/cf_blue"
/>
<TextView
android:id="@+id/carerinforelationship"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="5"
/>
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:id="@+id/carerinfodoblabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="DOB: "
android:layout_weight="1"
android:textColor="@color/cf_blue"
/>
<TextView
android:id="@+id/carerinfodob"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="5"
/>
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:id="@+id/carerinfopinlabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="PIN: "
android:layout_weight="1"
android:textColor="@color/cf_blue"
/>
<TextView
android:id="@+id/carerinfopin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="5"
/>
</LinearLayout>
</LinearLayout>
因为'wrap_content' – njzk2