对齐TextView彼此 - Android
我有2个文本视图在布局中。 第一个是在左边和右边 第一个第二个应该有80% 的宽度和第二应该有20%的宽度对齐TextView彼此 - Android
我怎么能做到吗?
,我无法找出该选择哪种布局:线性布局或相对布局
谢谢!
可以用户线性布局与重量特性80和20
<LinearLayout
android:orientation="horizontal"
android:layout_height="40dp"
android:layout_width="match_parent">
<TextView
android:text="yes"
android:layout_width="0dp"
android:layout_weight="80"
android:layout_height="40dp"
android:id="@+id/textViewOne"
android:textStyle="bold"
android:textSize="17sp"/>
<TextView
android:text="No"
android:layout_width="0dp"
android:layout_weight="20"
android:layout_height="40dp"
android:id="@+id/textViewTwo"
android:textStyle="bold"
android:textSize="17sp" />
</LinearLayout>
谢谢你的工作 –
可以使用的LinearLayout的每个孩子享有weightSum财产和layout_weight。简单地说:
<LinearLayout
android:orientation="horizontal"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:weight_sum="100">
<TextView
android:layout_width="0dp"
android:layout_weight="80"
android:layout_height="wrap_content"/>
<TextView
android:layout_width="0dp"
android:layout_weight="20"
android:layout_height="wrap_content" />
</LinearLayout>
谢谢你的帮助 –
不客气。很高兴我可以帮助:) @ElieDaher –
使用LinearLayout。它提供了以layout_weight和weightSum属性的形式指定百分比宽度或高度的工具。
<LinearLayout
android:orientation="horizontal"
android:weightSum="10"
android:layout_height="wrap_content"
android:layout_width="match_parent">
<TextView
android:text="first text view"
android:layout_width="0dp"
android:layout_weight="8"
android:layout_height="wrap_content"
/>
<TextView
android:text="second text view"
android:layout_width="0dp"
android:layout_weight="2"
android:layout_height="wrap_content"
/>
</LinearLayout>
应该工作。这里的权重总和为10,分为权重8和2,即80%和20%。将解决你的问题。
谢谢你的帮助 –
使用'LinearLayout'使用重量来定义视图你在问什么 – Pankaj