Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/208.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_Xml_Layout - Fatal编程技术网

Android 相同高度的定心布局

Android 相同高度的定心布局,android,xml,layout,Android,Xml,Layout,我无法通过imgur上传图像,因此我将通过驱动器发布链接: 以下是xml: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:la

我无法通过imgur上传图像,因此我将通过驱动器发布链接:

以下是xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">
        <LinearLayout
            android:id="@+id/lay"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">

            <ImageView
                android:id="@+id/imgView"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:src="@mipmap/ic_launcher"
                android:layout_weight="1"/>

            <ImageView
                android:id="@+id/imgView2"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:src="@mipmap/ic_launcher"
                android:layout_weight="1"/>
        </LinearLayout>
        <LinearLayout
            android:id="@+id/lay2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/lay"
            android:orientation="horizontal">

            <ImageView
                android:id="@+id/imgView3"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:src="@mipmap/ic_launcher"
                android:layout_weight="1"/>

            <ImageView
                android:id="@+id/imgView4"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:src="@mipmap/ic_launcher"
                android:layout_weight="1"/>
        </LinearLayout>

    </LinearLayout>

    <Button
        android:id="@+id/buttonLoadPicture"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Load Picture"
        android:layout_centerInParent="true"
        android:layout_alignParentBottom="true"/>
</RelativeLayout>

我需要的是制作布局中心,如下所示:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:weightSum="2">
        <LinearLayout
            android:id="@+id/lay"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:weightSum="2"
            android:orientation="horizontal">

            <ImageView
                android:id="@+id/imgView"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:src="@mipmap/ic_launcher"
                android:layout_weight="1"/>

            <ImageView
                android:id="@+id/imgView2"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:src="@mipmap/ic_launcher"
                android:layout_weight="1"/>
        </LinearLayout>
        <LinearLayout
            android:id="@+id/lay2"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_below="@+id/lay"
            android:orientation="horizontal"
            android:layout_weight="1"
            android:weightSum="2">

            <ImageView
                android:id="@+id/imgView3"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:src="@mipmap/ic_launcher"
                android:layout_weight="1"/>

            <ImageView
                android:id="@+id/imgView4"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:src="@mipmap/ic_launcher"
                android:layout_weight="1"/>
        </LinearLayout>

    </LinearLayout>

    <Button
        android:id="@+id/buttonLoadPicture"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Load Picture"
        android:layout_centerInParent="true"
        android:layout_alignParentBottom="true"/>
</RelativeLayout>


请帮忙,提前谢谢

您也应该在垂直布局中使用
权重

请尝试此代码。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">
        <LinearLayout
            android:id="@+id/lay"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:orientation="horizontal">

            <ImageView
                android:id="@+id/imgView"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:src="@mipmap/ic_launcher"
                android:layout_weight="1"/>

            <ImageView
                android:id="@+id/imgView2"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:src="@mipmap/ic_launcher"
                android:layout_weight="1"/>
        </LinearLayout>
        <LinearLayout
            android:id="@+id/lay2"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_below="@+id/lay"
            android:orientation="horizontal"
            android:layout_weight="1">

            <ImageView
                android:id="@+id/imgView3"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:src="@mipmap/ic_launcher"
                android:layout_weight="1"/>

            <ImageView
                android:id="@+id/imgView4"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:src="@mipmap/ic_launcher"
                android:layout_weight="1"/>
        </LinearLayout>

    </LinearLayout>

    <Button
        android:id="@+id/buttonLoadPicture"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Load Picture"
        android:layout_centerInParent="true"
        android:layout_alignParentBottom="true"/>
</RelativeLayout>

您也应该在垂直布局中使用
权重。

请尝试此代码。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">
        <LinearLayout
            android:id="@+id/lay"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:orientation="horizontal">

            <ImageView
                android:id="@+id/imgView"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:src="@mipmap/ic_launcher"
                android:layout_weight="1"/>

            <ImageView
                android:id="@+id/imgView2"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:src="@mipmap/ic_launcher"
                android:layout_weight="1"/>
        </LinearLayout>
        <LinearLayout
            android:id="@+id/lay2"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_below="@+id/lay"
            android:orientation="horizontal"
            android:layout_weight="1">

            <ImageView
                android:id="@+id/imgView3"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:src="@mipmap/ic_launcher"
                android:layout_weight="1"/>

            <ImageView
                android:id="@+id/imgView4"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:src="@mipmap/ic_launcher"
                android:layout_weight="1"/>
        </LinearLayout>

    </LinearLayout>

    <Button
        android:id="@+id/buttonLoadPicture"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Load Picture"
        android:layout_centerInParent="true"
        android:layout_alignParentBottom="true"/>
</RelativeLayout>

必须将
weightSum
属性添加到LinearLayout,并为图像视图的
android:layout\u width
设置
0dp
,如下所示:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:weightSum="2">
        <LinearLayout
            android:id="@+id/lay"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:weightSum="2"
            android:orientation="horizontal">

            <ImageView
                android:id="@+id/imgView"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:src="@mipmap/ic_launcher"
                android:layout_weight="1"/>

            <ImageView
                android:id="@+id/imgView2"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:src="@mipmap/ic_launcher"
                android:layout_weight="1"/>
        </LinearLayout>
        <LinearLayout
            android:id="@+id/lay2"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_below="@+id/lay"
            android:orientation="horizontal"
            android:layout_weight="1"
            android:weightSum="2">

            <ImageView
                android:id="@+id/imgView3"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:src="@mipmap/ic_launcher"
                android:layout_weight="1"/>

            <ImageView
                android:id="@+id/imgView4"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:src="@mipmap/ic_launcher"
                android:layout_weight="1"/>
        </LinearLayout>

    </LinearLayout>

    <Button
        android:id="@+id/buttonLoadPicture"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Load Picture"
        android:layout_centerInParent="true"
        android:layout_alignParentBottom="true"/>
</RelativeLayout>

必须将
weightSum
属性添加到LinearLayout,并为图像视图的
android:layout\u width
设置
0dp
,如下所示:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:weightSum="2">
        <LinearLayout
            android:id="@+id/lay"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:weightSum="2"
            android:orientation="horizontal">

            <ImageView
                android:id="@+id/imgView"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:src="@mipmap/ic_launcher"
                android:layout_weight="1"/>

            <ImageView
                android:id="@+id/imgView2"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:src="@mipmap/ic_launcher"
                android:layout_weight="1"/>
        </LinearLayout>
        <LinearLayout
            android:id="@+id/lay2"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_below="@+id/lay"
            android:orientation="horizontal"
            android:layout_weight="1"
            android:weightSum="2">

            <ImageView
                android:id="@+id/imgView3"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:src="@mipmap/ic_launcher"
                android:layout_weight="1"/>

            <ImageView
                android:id="@+id/imgView4"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:src="@mipmap/ic_launcher"
                android:layout_weight="1"/>
        </LinearLayout>

    </LinearLayout>

    <Button
        android:id="@+id/buttonLoadPicture"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Load Picture"
        android:layout_centerInParent="true"
        android:layout_alignParentBottom="true"/>
</RelativeLayout>