我需要右对齐 textview,但因为我使用的是layout_weight
,所以我需要设置layout_width="0dip"
. 设置layout_width="wrap_content"
打破了我的布局。
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:weightSum="2" >
<TextView
android:id="@+id/textView1"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="0.95"
android:gravity="center_vertical|right"
android:text="name" />
<TextView
android:id="@+id/textView1"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="0.1"
android:gravity="center_vertical|center"
android:text="=" />
<TextView
android:id="@+id/textView2"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="0.95"
android:gravity="center_vertical|left"
android:text="value" />
</LinearLayout>
目的是使名称-值对与行的中心对齐,如下所示:
我所有的搜索都只产生了设置 layout_width="wrap_content" 的解决方案,这在此处不起作用。有什么建议么?