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

Android 定位具有多个包含的布局

Android 定位具有多个包含的布局,android,layout,Android,Layout,为什么: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity" &

为什么:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity" >

    <include 
        layout="@layout/myCustomTitleBar"
        android:id="@+id/titlebar" />

    <include
        layout="@layout/myCustomToolBar"
        android:id="@+id/toolbar"
        android:layout_below="@id/titlebar" />

    <com.myname.myapp.MyCustomView
        android:id="@+id/myView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/toolbar"
    />

</RelativeLayout>

没有工作?
两个
include
s相互堆叠/重叠。(
下面的布局_
不起作用)
include
s--
myCustomTitleBar
myCustomToolBar
--都是
RelativeLayout
s.
我做错什么了吗

预期结果:


尝试将android:layout\u alignParentTop=“true”添加到标题栏

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity" >

    <include 
        layout="@layout/myCustomTitleBar"
        android:id="@+id/titlebar"
        android:layout_alignParentTop="true" />

    <include
        layout="@layout/myCustomToolBar"
        android:id="@+id/toolbar"
        android:layout_below="@id/titlebar" />

    <com.myname.myapp.MyCustomView
        android:id="@+id/myView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/toolbar"
    />

</RelativeLayout>

尝试将android:layout\u alignParentTop=“true”添加到标题栏

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity" >

    <include 
        layout="@layout/myCustomTitleBar"
        android:id="@+id/titlebar"
        android:layout_alignParentTop="true" />

    <include
        layout="@layout/myCustomToolBar"
        android:id="@+id/toolbar"
        android:layout_below="@id/titlebar" />

    <com.myname.myapp.MyCustomView
        android:id="@+id/myView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/toolbar"
    />

</RelativeLayout>

根据你的应用程序草图,你不应该使用
RelativeLayout
作为根用户
RelativeLayout
正是用于覆盖项目的。您必须使用
LinearLayout
。当然,LinearLayout组的每个项目都必须具有适当的
layout\u width/layout\u height

根目录:

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:layout_width="match_parent"
              android:layout_height="match_parent">

    <include layout="@layout/relative_sample_a"/>

    <include layout="@layout/relative_sample_b"/>

    <RelativeLayout android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:background="#991022"/>

</LinearLayout>

相对样本a.xml

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:background="#AACC33">

    <Button android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="10dp"
            android:text="ButtonA"/>

    <Button android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="10dp"
            android:layout_alignParentRight="true"
            android:text="ButtonB"/>


</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:background="#DDBB00">

    <Button android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="10dp"
            android:layout_centerInParent="true"
            android:text="ButtonC"/>


</RelativeLayout>

相对样本.xml

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:background="#AACC33">

    <Button android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="10dp"
            android:text="ButtonA"/>

    <Button android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="10dp"
            android:layout_alignParentRight="true"
            android:text="ButtonB"/>


</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:background="#DDBB00">

    <Button android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="10dp"
            android:layout_centerInParent="true"
            android:text="ButtonC"/>


</RelativeLayout>


根据你的应用程序草图,你不应该使用
RelativeLayout
作为根用户
RelativeLayout
正是用于覆盖项目的。您必须使用
LinearLayout
。当然,LinearLayout组的每个项目都必须具有适当的
layout\u width/layout\u height

根目录:

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:layout_width="match_parent"
              android:layout_height="match_parent">

    <include layout="@layout/relative_sample_a"/>

    <include layout="@layout/relative_sample_b"/>

    <RelativeLayout android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:background="#991022"/>

</LinearLayout>

相对样本a.xml

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:background="#AACC33">

    <Button android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="10dp"
            android:text="ButtonA"/>

    <Button android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="10dp"
            android:layout_alignParentRight="true"
            android:text="ButtonB"/>


</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:background="#DDBB00">

    <Button android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="10dp"
            android:layout_centerInParent="true"
            android:text="ButtonC"/>


</RelativeLayout>

相对样本.xml

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:background="#AACC33">

    <Button android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="10dp"
            android:text="ButtonA"/>

    <Button android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="10dp"
            android:layout_alignParentRight="true"
            android:text="ButtonB"/>


</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:background="#DDBB00">

    <Button android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="10dp"
            android:layout_centerInParent="true"
            android:text="ButtonC"/>


</RelativeLayout>