【问题标题】:Two frame layouts inside linear layout线性布局内的两个框架布局
【发布时间】:2014-11-07 18:24:49
【问题描述】:

这是我现在的代码:

<?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


    【解决方案1】:

    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>
    

    【讨论】:

    • LinearLayout标签中不应该有weightSum吗?
    • @AbdallahAlaraby 只需填写它就不需要 AFAIK
    【解决方案2】:
            <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>
    

    【讨论】:

    • 您能否详细说明问题所在以及您的答案是如何解决的? :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-11
    • 2014-04-30
    • 1970-01-01
    • 1970-01-01
    • 2017-08-26
    • 1970-01-01
    相关资源
    最近更新 更多