您的确可以为LinearLayout的水平和垂直方向分配权重。
水平方向例如:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<ImageView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight=".40" />
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight=".60" />
</LinearLayout>
垂直方位例如:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ImageView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight=".40" />
<TextView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight=".60" />
</LinearLayout>
顺便说一句,这是非常有用的知道,你不必指定浮点数的权重。 Android会简单地总结所有的权重,然后除以总数得到每个的百分比。因此,使用4和6分别为layout_weights也可以。
啊哈!关键是LinearLayout中的属性android:orientation =“vertical”。谢谢。 – rmhartman 2014-11-05 03:02:45