简体   繁体   English

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

[英]Linear layout overlapping another linear layout

I have two LinearLayouts in a RelativeLayout the problem is that the top linear layout is overlapping the bottom one a little bit.I tried everything. 我在RelativeLayout有两个LinearLayouts ,问题是顶部的线性布局与底部的线性布局有点重叠。 Please Somebody help me.Below is my XML File Or tell me how to do it programmatically. 请有人帮助我。以下是我的XML文件或告诉我如何以编程方式进行操作。 Like subtracting height of one linear layout from another. 就像从另一个线性布局中减去高度。

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

Try this: 尝试这个:

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

Use Relative Layout properties like 使用相对布局属性,例如

layout_below and layout_above layout_below和layout_above

Try following code: 尝试以下代码:

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

If the layouts are large and can't be accommodated in a single a screen then you should wrap both the linear layouts in a scrollView. 如果布局很大且无法容纳在单个屏幕中,则应将两个线性布局都包装在scrollView中。 Let me know if you face problem in using scrollView. 让我知道您在使用scrollView时是否遇到问题。

This is very easy you just have to set id to the Linear Layout at bottom like 这很容易,您只需要将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>`

you parent layout is linear layout so child is overlap each other 您的父级布局是线性布局,因此子级彼此重叠

use my code 用我的代码

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM