另一种布局的布局

时间:2018-01-09 17:02:56

标签: android android-layout

我需要一个布局而不是另一个布局(它们可以有任何高度),如下所示:

enter image description here

当屏幕变小时,我需要棕色布局变得更低,如下所示:

enter image description here

我有这个代码来执行此操作:

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

    <FrameLayout
        android:layout_width="100dp"
        android:layout_height="wrap_content"
        android:layout_gravity="top|center_horizontal"
        android:background="#dd6600">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="100dp"
            android:text="One"/>
    </FrameLayout>

    <FrameLayout
        android:layout_width="150dp"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|center_horizontal"
        android:background="#bbbbbb">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="150dp"
            android:text="Another"/>
    </FrameLayout>

</FrameLayout>

在小高度它工作正常,但在大屏幕上我有这个:

enter image description here

你能帮帮我吗?

3 个答案:

答案 0 :(得分:0)

您可以从CoordinatorLayout here中受益,以实现此类效果

答案 1 :(得分:0)

使用具有百分比权重的线性布局,以便尽管分辨率与

中的分辨率相同,但屏幕覆盖的百分比将始终相同
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="top"
android:orientation="vertical"
android:weightSum="1">
<FrameLayout
        android:layout_width="100dp"
        android:layout_height="0dp"
        android:layout_weight ="0.6"
        android:layout_gravity="top|center_horizontal"
        android:background="#dd6600">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="100dp"
            android:text="One"/>
    </FrameLayout>
<LinearLayout/>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="bottom"
android:orientation="vertical"
android:weightSum="1">
    <FrameLayout
        android:layout_width="150dp"
        android:layout_height="0dp"
        android:layout_weight ="0.6"
        android:layout_gravity="bottom|center_horizontal"
        android:background="#bbbbbb">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="150dp"
            android:text="Another"/>
    </FrameLayout>
</LinearLayout/>

答案 2 :(得分:0)

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
         android:layout_width="match_parent"
         android:layout_height="match_parent"
         android:gravity="center">

<FrameLayout
    android:layout_width="100dp"
    android:layout_height="wrap_content"
    android:layout_gravity="top|center_horizontal"
    android:background="#dd6600">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="100dp"
        android:text="One"/>
</FrameLayout>

<FrameLayout
    android:layout_width="150dp"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|center_horizontal"
    android:layout_marginTop="70dp"
    android:background="#bbbbbb">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="150dp"
        android:text="Another"/>
</FrameLayout>

使用RelativeLayout并将android:layout_marginTop="70dp"添加到RelativeLayout的第二个孩子。您可以根据您的要求更改保证金。