在android中有百分比宽度的任何选项吗?我试图将我的2行设置为40%,将文本设置为20%,但我真的不知道如何实现此目标。我现在有固定的宽度。线性布局中的线条宽度百分比
<LinearLayout
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:weightSum="1">
<ImageView
android:layout_width="wrap_content"
android:layout_height="14dp"
android:id="@+id/line2"
android:background="@drawable/line"
android:layout_gravity="center_horizontal"
android:contentDescription="@string/line" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="@string/or"
android:textAllCaps="true"
android:gravity="center"
android:id="@+id/textView"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="@+id/imageView"
android:background="@drawable/line"
android:layout_gravity="center_horizontal"
android:layout_weight="2.18"
android:contentDescription="@string/line" />
</LinearLayout>
这是机器人工作室屏幕更好的理解:screen
您是否尝试使用小部件的重量?这将有助于 – Amsheer 2014-11-14 13:01:51
使用新的百分比支持库,现在可以使用百分比布局。 [查看此链接](https://github.com/JulienGenoud/android-percent-support-lib-sample) – kleinsenberg 2015-07-20 22:18:26