1

我正在尝试创建一个包含三个片段和两个按钮按钮栏的主细节 UI。由于某种原因,添加按钮栏后,片段未显示在 UI 中。我怀疑它与布局的方向有关,但我将把它留给这里的专家。

添加按钮栏之前

添加按钮栏后

这是 UI 的 XML 布局

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:baselineAligned="false"
android:orientation="horizontal" >

<fragment
    android:id="@+id/mainBodyFragment"
    android:layout_width="0dp"
    android:layout_height="match_parent"
    android:layout_weight="1"
    class="com.dreamcode.healttracker.MainBodyArea" />

<fragment
    android:id="@+id/subBodyFragment"
    android:layout_width="0dp"
    android:layout_height="match_parent"
    android:layout_weight="1"
    class="com.dreamcode.healttracker.SubBodyArea" />

<fragment
    android:id="@+id/symptomFragment"
    android:layout_width="0dp"
    android:layout_height="match_parent"
    android:layout_weight="3"
    class="com.dreamcode.healttracker.Symptom" />

<LinearLayout
    android:id="@+id/footer"
    style="@android:style/ButtonBar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom"
    android:background="#F0F0F0"
    android:orientation="horizontal" >

    <Button
        android:id="@+id/btn_Generate"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:background="@drawable/borderless_button"
        android:text="@string/generate" />

    <View
        android:layout_width="1dp"
        android:layout_height="fill_parent"
        android:background="#909090" />

    <Button
        android:id="@+id/btn_ViewList"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:background="@drawable/borderless_button"
        android:text="@string/viewlist" />
</LinearLayout>

</LinearLayout>
4

2 回答 2

0

您的第一个LinearLayout具有水平方向(因此所有内容都将与其他内容相邻),而不是您将按钮栏添加为width="match_parent",因此按钮栏使用保持垂直空间。如果您想将片段放在彼此下方,请将orientation第一个片段更改为垂直。如果片段应该彼此相邻并且下面的按钮栏使用以下代码:(第一个LinearLayout未在您的代码中关闭!)

<?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:baselineAligned="false"
    android:orientation="vertical" >
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">
<fragment
    android:id="@+id/mainBodyFragment"
    android:layout_width="0dp"
    android:layout_height="match_parent"
    android:layout_weight="1"
    class="com.dreamcode.healttracker.MainBodyArea" />

<fragment
    android:id="@+id/subBodyFragment"
    android:layout_width="0dp"
    android:layout_height="match_parent"
    android:layout_weight="1"
    class="com.dreamcode.healttracker.SubBodyArea" />

<fragment
    android:id="@+id/symptomFragment"
    android:layout_width="0dp"
    android:layout_height="match_parent"
    android:layout_weight="3"
    class="com.dreamcode.healttracker.Symptom" />
</LinearLayout> <!-- added -->
<LinearLayout
    android:id="@+id/footer"
    style="@android:style/ButtonBar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom"
    android:background="#F0F0F0"
    android:orientation="horizontal" >

<Button
    android:id="@+id/btn_Generate"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:background="@drawable/borderless_button"
    android:text="@string/generate" />

<View
    android:layout_width="1dp"
    android:layout_height="fill_parent"
    android:background="#909090" />

<Button
    android:id="@+id/btn_ViewList"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:background="@drawable/borderless_button"
    android:text="@string/viewlist" />
</LinearLayout>
</LinearLayout> 
于 2014-04-14T19:25:08.863 回答
0

这应该可以解决问题:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <LinearLayout
        android:id="@+id/footer"
        style="@android:style/ButtonBar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:background="#F0F0F0"
        android:orientation="horizontal" >

        <Button
            android:id="@+id/btn_Generate"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="@drawable/borderless_button"
            android:text="@string/generate" />

        <View
            android:layout_width="1dp"
            android:layout_height="fill_parent"
            android:background="#909090" />

        <Button
            android:id="@+id/btn_ViewList"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="@drawable/borderless_button"
            android:text="@string/viewlist" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@id/footer"
        android:baselineAligned="false"
        android:orientation="horizontal" >

        <fragment
            android:id="@+id/mainBodyFragment"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            class="com.dreamcode.healttracker.MainBodyArea" />

        <fragment
            android:id="@+id/subBodyFragment"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            class="com.dreamcode.healttracker.SubBodyArea" />

        <fragment
            android:id="@+id/symptomFragment"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="3"
            class="com.dreamcode.healttracker.Symptom" />
    </LinearLayout>

</RelativeLayout>
于 2014-04-14T20:02:56.857 回答