Android 如何使嵌套线性布局占据父布局的一半
在我最外层的布局管理器中,我有:Android 如何使嵌套线性布局占据父布局的一半,android,Android,在我最外层的布局管理器中,我有: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:layout_margin="2dp" android:id="
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:orientation="horizontal" android:layout_margin="2dp"
android:id="@+id/linearlayout1" android:layout_weight="1">
<com.me.android.ui.ImageView
android:id="@+id/artistimage" android:layout_height="177dp"
android:layout_width="wrap_content" android:scaleType="centerCrop"
android:layout_margin="5dp" />
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:orientation="vertical" android:layout_alignParentTop="true"
android:layout_weight="1">
<TextView android:layout_height="wrap_content"
android:textSize="24dp" android:paddingBottom="5dp"
android:textStyle="bold" android:paddingLeft="5dp"
android:paddingTop="5dp" android:layout_width="fill_parent"
android:textColor="@color/redtext" android:id="@+id/artistname" />
<ToggleButton android:id="@+id/artistfav"
android:layout_alignParentRight="true" android:background="@drawable/favbutton"
android:textOff=" " android:textOn=" " android:layout_marginTop="5dp"
android:layout_width="fill_parent" android:layout_height="30dp"
android:layout_marginRight="10dp" android:text="Add to Favorites"
android:scaleType="fitXY" />
</LinearLayout>
</LinearLayout>
由于外部
线性布局
是水平的
,因此将其子项的android:layout_width
设置为0dip
。然后,android:layou weight
将单独控制大小。由于外部线性布局是水平的
,因此将其子级的android:layou width
设置为0dip
。然后,android:layou-weight
将单独控制大小。好吧,这就是我的工作原理:
<com.me.android.ui.ImageView
android:id="@+id/artistimage" android:layout_height="150dp"
android:layout_width="fill_parent" android:scaleType="centerCrop"
android:layout_margin="5dp" android:layout_weight="1" />
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:orientation="vertical" android:layout_weight="1" >
<TextView android:layout_height="wrap_content"
android:textSize="22dp" android:paddingBottom="5dp"
android:textStyle="bold" android:paddingLeft="5dp"
android:paddingTop="5dp" android:layout_width="fill_parent"
android:textColor="@color/redtext" android:id="@+id/artistname"/>
<ToggleButton android:id="@+id/artistfav"
android:layout_alignParentRight="true" android:background="@drawable/favbutton"
android:textOff=" " android:textOn=" " android:layout_marginTop="5dp"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_marginRight="10dp"
/>
</LinearLayout>
</LinearLayout>
好吧,这就是我的工作原理:
<com.me.android.ui.ImageView
android:id="@+id/artistimage" android:layout_height="150dp"
android:layout_width="fill_parent" android:scaleType="centerCrop"
android:layout_margin="5dp" android:layout_weight="1" />
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:orientation="vertical" android:layout_weight="1" >
<TextView android:layout_height="wrap_content"
android:textSize="22dp" android:paddingBottom="5dp"
android:textStyle="bold" android:paddingLeft="5dp"
android:paddingTop="5dp" android:layout_width="fill_parent"
android:textColor="@color/redtext" android:id="@+id/artistname"/>
<ToggleButton android:id="@+id/artistfav"
android:layout_alignParentRight="true" android:background="@drawable/favbutton"
android:textOff=" " android:textOn=" " android:layout_marginTop="5dp"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_marginRight="10dp"
/>
</LinearLayout>
</LinearLayout>
您已将textview和button的宽度指定为0,以解释其不可见的原因您已将textview和button的宽度指定为0,以解释其不可见的原因谢谢标记。只是为了确保我们清楚。这两个linearlayout嵌套在另一个linearlayout中(我没有在OP中复制它)…我很困惑。。。不能让它工作。将子线性布局
(垂直布局)的布局宽度设置为0dip
?或者将imageview
设置为0dip
?尝试了所有组合,但似乎无法正常工作。您的意思是将线性布局的布局宽度设置为0dip
,然后在这些布局上设置布局权重
?如果我那样做,一切都会消失…@LuxuryMode:谢谢你,马克。只是为了确保我们清楚。这两个linearlayout嵌套在另一个linearlayout中(我没有在OP中复制它)…我很困惑。。。不能让它工作。将子线性布局
(垂直布局)的布局宽度设置为0dip
?或者将imageview
设置为0dip
?尝试了所有组合,但似乎无法正常工作。您的意思是将线性布局的布局宽度设置为0dip
,然后在这些布局上设置布局权重
?如果我那样做,一切都会消失…@LuxuryMode:看到了吗