Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/194.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 跨越2个片段的按钮(xml布局)_Android_Xml - Fatal编程技术网

Android 跨越2个片段的按钮(xml布局)

Android 跨越2个片段的按钮(xml布局),android,xml,Android,Xml,无法理解如何在XML中设置此项 试图得到一个按钮来覆盖它后面的两个碎片 我想要的是: 我所拥有的: 我的代码: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_w

无法理解如何在XML中设置此项

试图得到一个按钮来覆盖它后面的两个碎片

我想要的是:

我所拥有的:

我的代码:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
    android:orientation="horizontal"
    tools:context=".VulgarActivity" 
    >
    <Button
        android:id="@+id/luckBtn"
        android:layout_gravity="bottom"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/feel_lucky"
        android:textColor="#ffffff"
        />
    <fragment
        android:name="com.wizardknight.visionaryvulgarity.FirstWord"
        android:id="@+id/firstWord"
        android:layout_weight="1"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        />
    <fragment
        android:name="com.wizardknight.visionaryvulgarity.LastWord"
        android:id="@+id/lastWord"
        android:layout_weight="1"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        />  
</LinearLayout>

您可以使用
RelativeLayout

<?xml version="1.0" encoding="utf-8"?>
<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"
    android:orientation="horizontal" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

        <fragment
            android:id="@+id/firstWord"
            android:name="com.wizardknight.visionaryvulgarity.FirstWord"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1" />

        <fragment
            android:id="@+id/lastWord"
            android:name="com.wizardknight.visionaryvulgarity.LastWord"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1" />
    </LinearLayout>

    <Button
        android:id="@+id/luckBtn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:layout_gravity="bottom"
        android:text="@string/feel_lucky"
        android:textColor="#ffffff" />

</RelativeLayout>

这将使按钮与底部对齐,并使其水平居中。现在,由于它是相对于顶层布局执行此操作的,因此它与片段重叠。

您可以使用
RelativeLayout来执行此操作:

<?xml version="1.0" encoding="utf-8"?>
<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"
    android:orientation="horizontal" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

        <fragment
            android:id="@+id/firstWord"
            android:name="com.wizardknight.visionaryvulgarity.FirstWord"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1" />

        <fragment
            android:id="@+id/lastWord"
            android:name="com.wizardknight.visionaryvulgarity.LastWord"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1" />
    </LinearLayout>

    <Button
        android:id="@+id/luckBtn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:layout_gravity="bottom"
        android:text="@string/feel_lucky"
        android:textColor="#ffffff" />

</RelativeLayout>

这将使按钮与底部对齐,并使其水平居中。现在,由于它与顶层布局相关,因此与片段重叠。

非常感谢。。。现在让我问一个问题。我尝试了嵌套的线性布局,最终使它们彼此相邻,而不是相互重叠。这是我第一次使用碎片,所以我做了一些愚蠢和有趣的练习。。。什么是相对布局,允许这些堆叠线性没有?感谢吨。。。现在让我问一个问题。我尝试了嵌套的线性布局,最终使它们彼此相邻,而不是相互重叠。这是我第一次使用碎片,所以我做了一些愚蠢和有趣的练习。。。什么是相对布局,允许这些堆叠线性没有?