textView 对齐错误。我想在红线上对齐所有正确的 textView
Wrong alignment of textView. I want to make there alignment of all right textView on the redline
我将其创建为自定义对话框。我正在使用两个文本视图,左一个和右一个。我正在使用回收器来显示此对话框。
我希望所有正确的 textView 都应该在红线上对齐。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingBottom="@dimen/regular_padding"
android:paddingLeft="@dimen/regular_padding"
android:paddingRight="@dimen/regular_padding">
<TextView
android:id="@+id/iet_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/colorPrimaryDark"
tools:text="Email" />
<TextView
android:id="@+id/iet_desc_text"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/half_padding"
android:layout_weight="1"
android:textColor="@color/colorPrimaryDark"
tools:text="Email" />
</LinearLayout>
如果您的标题是静态的,您可以只为 "iet_title" TextView
设置一个静态宽度:
<TextView
android:id="@+id/iet_title"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:textColor="@color/colorPrimaryDark"
tools:text="Email" />
<?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="wrap_content"
android:orientation="horizontal"
android:weightSum="1">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_weight="0.8">
<TextView
android:id="@+id/iet_title1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="left"
android:text="Email" />
<TextView
android:id="@+id/iet_desc_text1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="left"
android:text="Subject" />
<TextView
android:id="@+id/iet_desc_body"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="left"
android:text="Body" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_weight="0.2">
<TextView
android:id="@+id/iet_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="left"
android:text="Dymmy@gmail.com" />
<TextView
android:id="@+id/iet_desc_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="left"
android:text="Dummy task" />
<TextView
android:id="@+id/iet_desc_body1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="left"
android:text="down vote favorite I have created this as custom dialog. I am using two text views left one and the right one. I am using recycler to display this Dialog.Email kbjhklilkilili" />
</LinearLayout>
</LinearLayout>
您应该使用 2 列 3 行的 TableLayout。看起来不错,你所有的元素都会被正确排列。
参考此文档:Android TableLayout
将 weightsum=1 添加到您的父布局。
所有子布局宽度匹配父布局重量 = 0.5。您可以根据需要更改布局权重。
我认为最好的方法是使用重量。一个工作代码
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:orientation="horizontal"
android:weightSum="4">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Email:" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3"
android:text="safallwa.aas@gmail.com" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:orientation="horizontal"
android:weightSum="4">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Subject:" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3"
android:text="very interesting subject" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:orientation="horizontal"
android:weightSum="4">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Body:" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3"
android:text="Lorem Ipsum is simply dummy text of the printing and typesetting industry." />
</LinearLayout>
输出为
我将其创建为自定义对话框。我正在使用两个文本视图,左一个和右一个。我正在使用回收器来显示此对话框。
我希望所有正确的 textView 都应该在红线上对齐。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingBottom="@dimen/regular_padding"
android:paddingLeft="@dimen/regular_padding"
android:paddingRight="@dimen/regular_padding">
<TextView
android:id="@+id/iet_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/colorPrimaryDark"
tools:text="Email" />
<TextView
android:id="@+id/iet_desc_text"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/half_padding"
android:layout_weight="1"
android:textColor="@color/colorPrimaryDark"
tools:text="Email" />
</LinearLayout>
如果您的标题是静态的,您可以只为 "iet_title" TextView
设置一个静态宽度:
<TextView
android:id="@+id/iet_title"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:textColor="@color/colorPrimaryDark"
tools:text="Email" />
<?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="wrap_content"
android:orientation="horizontal"
android:weightSum="1">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_weight="0.8">
<TextView
android:id="@+id/iet_title1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="left"
android:text="Email" />
<TextView
android:id="@+id/iet_desc_text1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="left"
android:text="Subject" />
<TextView
android:id="@+id/iet_desc_body"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="left"
android:text="Body" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_weight="0.2">
<TextView
android:id="@+id/iet_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="left"
android:text="Dymmy@gmail.com" />
<TextView
android:id="@+id/iet_desc_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="left"
android:text="Dummy task" />
<TextView
android:id="@+id/iet_desc_body1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="left"
android:text="down vote favorite I have created this as custom dialog. I am using two text views left one and the right one. I am using recycler to display this Dialog.Email kbjhklilkilili" />
</LinearLayout>
</LinearLayout>
您应该使用 2 列 3 行的 TableLayout。看起来不错,你所有的元素都会被正确排列。
参考此文档:Android TableLayout
将 weightsum=1 添加到您的父布局。 所有子布局宽度匹配父布局重量 = 0.5。您可以根据需要更改布局权重。
我认为最好的方法是使用重量。一个工作代码
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:orientation="horizontal"
android:weightSum="4">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Email:" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3"
android:text="safallwa.aas@gmail.com" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:orientation="horizontal"
android:weightSum="4">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Subject:" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3"
android:text="very interesting subject" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:orientation="horizontal"
android:weightSum="4">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Body:" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3"
android:text="Lorem Ipsum is simply dummy text of the printing and typesetting industry." />
</LinearLayout>
输出为