线性布局内的两个框架布局

问题描述 投票:3回答:2

这是我现在的代码:

<?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:orientation="vertical" >

    <FrameLayout
        android:id="@+id/tablet_locations_fragment_fragment_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <FrameLayout
        android:id="@+id/tablet_locations_fragment_locations_fragment_list_container"
        android:layout_width="match_parent"
        android:layout_height="90dp" />

</LinearLayout>

我认为很明显,我希望底部框架布局为90dp高和高,以占用剩余的空间,但目前,上部框架布局占据了所有的屏幕高度。我怎样才能解决这个问题?我试图将layout_height =“wrap_content”用于上部框架布局,但它没有改变任何东西。

android android-linearlayout android-framelayout
2个回答
10
投票

layout_weight是你的朋友

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

    <FrameLayout
        android:id="@+id/tablet_locations_fragment_fragment_container"
        android:layout_width="match_parent"
        android:layout_weight="1"
        android:layout_height="0dp" />

    <FrameLayout
        android:id="@+id/tablet_locations_fragment_locations_fragment_list_container"
        android:layout_width="match_parent"
        android:layout_height="90dp" />

</LinearLayout>

0
投票
        <LinearLayout
            android:orientation="horizontal"
            android:layout_width="272dp"
            android:layout_weight="3"
            android:gravity="center_horizontal"
            android:layout_height="wrap_content">


            <FrameLayout
                android:layout_width="wrap_content"

                android:layout_height="wrap_content"
                >


                <fragment
                    android:layout_width="89dp"
                    android:layout_gravity="left|center_horizontal"
                    android:id="@+id/firstFragment"
                    android:name="com.androidipdetector.mbiplobe.actionbaractivity.Frag.Pressure"
                    android:layout_height="120dp"/>

                <fragment
                    android:layout_width="89dp"
                    android:layout_gravity="center|center_horizontal"
                    android:id="@+id/SecondFragment"
                    android:layout_marginLeft="100dp"
                    android:layout_marginRight="100dp"
                    android:name="com.androidipdetector.mbiplobe.actionbaractivity.Frag.SunsetFragment"
                    android:layout_height="120dp"/>

                <fragment
                    android:layout_width="89dp"
                    android:layout_gravity="right|center_horizontal"
                    android:id="@+id/thirdFragment"
                    android:name="com.androidipdetector.mbiplobe.actionbaractivity.Frag.SunsetFragment"
                    android:layout_height="120dp"/>

            </FrameLayout>

        </LinearLayout>
© www.soinside.com 2019 - 2024. All rights reserved.