代码之家  ›  专栏  ›  技术社区  ›  Jim Clermonts

如何用可用空间填充FrameLayout中的两个视图

  •  0
  • Jim Clermonts  · 技术社区  · 7 年前

    我有两种观点。我想要两个视图填满屏幕,就像线性布局一样。视图1应该位于右上角,并且应该更小。我需要FrameLayout,因为我在上面有更多的视图,所以这个问题是关于如何使用FrameLayout。

    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/videoScreen"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    
        <View
            android:id="@+id/view1"
            android:layout_width="match_parent"
            android:layout_height="400dp"
            android:layout_gravity="bottom"
            android:background="@android:color/holo_red_dark" />
    
        <View
            android:id="@+id/view2"
            android:layout_width="100dp"
            android:layout_height="110dp"
            android:layout_gravity="top|end"
            android:background="@android:color/holo_blue_bright" />
    
    </FrameLayout>
    

    对于Nexus4,它是有效的,但对于其他分辨率,它当然不起作用: enter image description here

    1 回复  |  直到 7 年前
        1
  •  0
  •   Greg Moens    7 年前

    像这样的?

    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/videoScreen"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    
        <LinearLayout
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="match_parent">
    
            <View
                android:id="@+id/view2"
                android:layout_width="100dp"
                android:layout_height="110dp"
                android:layout_gravity="end"
                android:background="@android:color/holo_blue_bright" />
    
            <View
                android:id="@+id/view1"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="1"
                android:background="@android:color/holo_red_dark" />
        </LinearLayout>
    
    </FrameLayout>