线性布局与另一个线性布局重叠

时间:2016-04-27 12:47:37

标签: java android user-interface

我在LinearLayouts中有两个RelativeLayout,问题是顶部线性布局与底部布局略有重叠。我尝试了一切。请有人帮助我.Below是我的XML文件 或者告诉我如何以编程方式执行此操作。就像从一个线性布局中减去另一个线性布局的高度一样。

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

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal"
        android:weightSum="1">

        <FrameLayout
            android:id="@+id/page_fragment"
            android:layout_width="150dp"
            android:layout_height="match_parent"
            android:background="@color/spinner_text_color" />

        <FrameLayout
            android:id="@+id/detail_fragment"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:background="@color/white_bg"
            android:layout_weight="1"></FrameLayout>
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:background="@color/spinner_text_color">

        <Button
            android:id="@+id/filterResetButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight=".50"
            android:textColor="@color/white_bg"
            android:textAllCaps="false"
            android:background="@drawable/light_button_click"
            android:text="Reset All" />

        <Button
            android:id="@+id/filterApplyButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight=".50"
            android:textAllCaps="false"
            android:background="@drawable/submit_order_click"
            android:textColor="@color/white_bg"
            android:text="Apply" />

    </LinearLayout>

</RelativeLayout>

5 个答案:

答案 0 :(得分:3)

试试这个:

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

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal"
        android:weightSum="1"
        android:layout_above="@+id/linearLayout">

        <FrameLayout
            android:id="@+id/page_fragment"
            android:layout_width="150dp"
            android:layout_height="match_parent"
            android:background="@color/colorPrimary" />

        <FrameLayout
            android:id="@+id/detail_fragment"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:background="@color/white"
            android:layout_weight="1"></FrameLayout>
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:background="@color/colorPrimary"
        android:id="@+id/linearLayout">

        <Button
            android:id="@+id/filterResetButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight=".50"
            android:textColor="@color/white"
            android:textAllCaps="false"
            android:background="@drawable/ic_authy"
            android:text="Reset All" />

        <Button
            android:id="@+id/filterApplyButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight=".50"
            android:textAllCaps="false"
            android:background="@drawable/ic_arrow_32"
            android:textColor="@color/white"
            android:text="Apply" />

    </LinearLayout>

</RelativeLayout>

答案 1 :(得分:1)

使用相对布局属性,如

  

layout_below和layout_above

答案 2 :(得分:0)

请尝试以下代码:

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

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_above="@+id/bottomLayout"
    android:orientation="horizontal"
    android:weightSum="1">

    <FrameLayout
        android:id="@+id/page_fragment"
        android:layout_width="150dp"
        android:layout_height="match_parent"
        android:background="@color/spinner_text_color" />

    <FrameLayout
        android:id="@+id/detail_fragment"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:background="@color/white_bg"
        android:layout_weight="1"></FrameLayout>
</LinearLayout>

<LinearLayout
    android:id="@+id/bottomLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:background="@color/spinner_text_color">

    <Button
        android:id="@+id/filterResetButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight=".50"
        android:textColor="@color/white_bg"
        android:textAllCaps="false"
        android:background="@drawable/light_button_click"
        android:text="Reset All" />

    <Button
        android:id="@+id/filterApplyButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight=".50"
        android:textAllCaps="false"
        android:background="@drawable/submit_order_click"
        android:textColor="@color/white_bg"
        android:text="Apply" />

  </LinearLayout>

</RelativeLayout>

如果布局很大并且无法容纳在单个屏幕中,那么您应该将两个线性布局包装在scrollView中。如果您在使用scrollView时遇到问题,请告诉我。

答案 3 :(得分:0)

这很简单,您只需将id设置为底部的线性布局,如

**android:id="@+id/bottom_linearlayout"**

and set the upper Linear Layout "above" over the bottom ones "id", like this

**android:layout_above="@id/bottom_linearlayout"**

`<?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:layout_above="@id/bottom_linearlayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal"
        android:weightSum="1">

        <FrameLayout
            android:id="@+id/page_fragment"
            android:layout_width="150dp"
            android:layout_height="match_parent"
            android:background="@color/spinner_text_color" />

        <FrameLayout
            android:id="@+id/detail_fragment"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:background="@color/white_bg"
            android:layout_weight="1"></FrameLayout>
    </LinearLayout>

    <LinearLayout
        android:id="@+id/bottom_linearlayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:background="@color/spinner_text_color">

        <Button
            android:id="@+id/filterResetButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight=".50"
            android:textColor="@color/white_bg"
            android:textAllCaps="false"
            android:text="Reset All" />

        <Button
            android:id="@+id/filterApplyButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight=".50"
            android:textAllCaps="false"
            android:textColor="@color/white_bg"
            android:text="Apply" />

    </LinearLayout>

</RelativeLayout>`

答案 4 :(得分:0)

你的父布局是线性布局,所以孩子彼此重叠

使用我的代码

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

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal"
        android:weightSum="1"
        android:layout_weight="90">

        <FrameLayout
            android:id="@+id/page_fragment"
            android:layout_width="150dp"
            android:layout_height="match_parent"
            android:background="@color/spinner_text_color" />

        <FrameLayout
            android:id="@+id/detail_fragment"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:background="@color/white_bg"
            android:layout_weight="1"></FrameLayout>
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="10"
        android:layout_alignParentBottom="true"
        android:background="@color/spinner_text_color">

        <Button
            android:id="@+id/filterResetButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight=".50"
            android:textColor="@color/white_bg"
            android:textAllCaps="false"
            android:background="@drawable/light_button_click"
            android:text="Reset All" />

        <Button
            android:id="@+id/filterApplyButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight=".50"
            android:textAllCaps="false"
            android:background="@drawable/submit_order_click"
            android:textColor="@color/white_bg"
            android:text="Apply" />

    </LinearLayout>

</LinearLayout>