Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/186.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何使嵌套线性布局占据父布局的一半_Android - Fatal编程技术网

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:看到了吗