【问题标题】:View aligned to parent bottom is hiding, while including relative layout inside coordinator layout与父底部对齐的视图被隐藏,同时包括协调器布局内的相对布局
【发布时间】:2018-08-27 06:40:42
【问题描述】:

我的协调器布局是

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/Drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">

<android.support.design.widget.CoordinatorLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:elevation="0dp">

        <android.support.v7.widget.Toolbar
            android:id="@+id/Toolbar"
            android:layout_width="match_parent"
            android:layout_height="?actionBarSize"
            android:background="@drawable/bg_horizon_gradient"
            android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
            app:layout_scrollFlags="scroll|enterAlways|snap"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

    </android.support.design.widget.AppBarLayout>

    <FrameLayout
        android:id="@+id/view_stub"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />

</android.support.design.widget.CoordinatorLayout>

<android.support.design.widget.NavigationView
    android:id="@+id/Navigation_view"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    app:headerLayout="@layout/navigation_header"
    app:itemTextColor="@android:color/holo_red_dark"
    app:menu="@menu/nav_drawer_menu" />

  </android.support.v4.widget.DrawerLayout>

我在框架布局中加入了相对布局。 我在与底部对齐的相对布局中有按钮布局(线性布局)。 但按钮布局根本不可见。 当我使用 linear layout 而不是 coordinator layout 时,按钮布局可见,但我无法在其中获得工具栏隐藏功能。 请帮帮我。 提前致谢。

我的相对布局是

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#fff"
tools:context=".ProductDetailPage">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="#fff"
    android:orientation="vertical">

    <ImageView
        android:id="@+id/productImage_field"
        android:layout_width="match_parent"
        android:layout_height="@dimen/_200sdp"
        android:layout_marginTop="@dimen/_5sdp"
        app:srcCompat="@mipmap/ic_launcher" />

    <View
        android:layout_width="match_parent"
        android:layout_height="@dimen/_1sdp"
        android:layout_marginBottom="@dimen/_10sdp"
        android:background="?attr/colorButtonNormal" />

    <android.support.v7.widget.CardView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="@dimen/_5sdp"
        android:layout_marginLeft="@dimen/_15sdp"
        app:cardCornerRadius="@dimen/_3sdp"
        app:cardElevation="@dimen/_5sdp">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@android:color/holo_orange_dark"
            android:paddingBottom="@dimen/_4sdp"
            android:paddingLeft="@dimen/_5sdp"
            android:paddingRight="@dimen/_5sdp"
            android:paddingTop="@dimen/_4sdp"
            android:text="20% OFF"
            android:textColor="#fff"
            android:textSize="@dimen/_12ssp" />
    </android.support.v7.widget.CardView>

    <TextView
        android:id="@+id/productCategory_field"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="@dimen/_3sdp"
        android:layout_marginLeft="@dimen/_15sdp"
        android:text="General Vegetables"
        android:textSize="@dimen/_12ssp"
        android:textStyle="bold" />

    <TextView
        android:id="@+id/productName_field"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="@dimen/_3sdp"
        android:layout_marginLeft="@dimen/_15sdp"
        android:text="Onions"
        android:textColor="#000"
        android:textSize="@dimen/_14ssp"
        android:textStyle="bold" />

    <TextView
        android:id="@+id/productSp_field"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="@dimen/_3sdp"
        android:layout_marginLeft="@dimen/_15sdp"
        android:text="MRP: Rs.40/-"
        android:textSize="@dimen/_12ssp"
        android:textStyle="bold" />

    <TextView
        android:id="@+id/productPrice_field"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="@dimen/_3sdp"
        android:layout_marginLeft="@dimen/_15sdp"
        android:text="FC's MRP: Rs.38/-"
        android:textColor="#000"
        android:textSize="@dimen/_15ssp"
        android:textStyle="bold" />

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="@dimen/_3sdp"
        android:layout_marginLeft="@dimen/_15sdp"
        android:text="Quantity"
        android:textColor="@color/colorPrimary"
        android:textSize="@dimen/_14ssp"
        android:textStyle="bold" />

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="@dimen/_3sdp"
        android:layout_marginLeft="@dimen/_15sdp"
        android:layout_marginRight="@dimen/_15sdp">

        <TextView
            android:id="@+id/quantity_field"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="1"
            android:textSize="@dimen/_18ssp" />

        <TextView
            android:id="@+id/item_txt"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="5dp"
            android:layout_toRightOf="@+id/quantity_field"
            android:text="kg"
            android:textSize="@dimen/_18ssp" />

        <TextView
            android:id="@+id/decreaseQuantity_btn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="false"
            android:layout_toLeftOf="@+id/increaseQuantity_btn"
            android:background="@android:color/darker_gray"
            android:onClick="decreaseInteger"
            android:paddingLeft="@dimen/_20sdp"
            android:paddingRight="@dimen/_20sdp"
            android:text="-"
            android:textColor="@android:color/background_light"
            android:textSize="@dimen/_18ssp"
            android:textStyle="bold" />

        <TextView
            android:id="@+id/increaseQuantity_btn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_marginLeft="@dimen/_10sdp"
            android:background="@android:color/holo_orange_dark"
            android:onClick="increaseInteger"
            android:paddingLeft="@dimen/_20sdp"
            android:paddingRight="@dimen/_20sdp"
            android:text="+"
            android:textColor="@android:color/background_light"
            android:textSize="@dimen/_18ssp"
            android:textStyle="bold" />
    </RelativeLayout>

    </LinearLayout>

   <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:background="#fff"
    android:gravity="center"
    android:orientation="horizontal">

    <android.support.v7.widget.CardView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="@dimen/_8sdp"
        android:layout_marginLeft="@dimen/_5sdp"
        android:layout_marginRight="@dimen/_5sdp"
        android:layout_marginTop="@dimen/_8sdp"
        app:cardCornerRadius="@dimen/_3sdp"
        app:cardElevation="@dimen/_4sdp">

        <TextView
            android:id="@+id/AddToCartFromProduct_field"
            android:layout_width="@dimen/_135sdp"
            android:layout_height="wrap_content"
            android:background="@drawable/bg_horizon_gradient"
            android:gravity="center"
            android:paddingBottom="@dimen/_10sdp"
            android:paddingTop="@dimen/_10sdp"
            android:text="ADD TO CART"
            android:textColor="#fff"
            android:textSize="@dimen/_14ssp"
            android:textStyle="bold" />
    </android.support.v7.widget.CardView>

    <android.support.v7.widget.CardView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="@dimen/_8sdp"
        android:layout_marginLeft="@dimen/_5sdp"
        android:layout_marginRight="@dimen/_5sdp"
        android:layout_marginTop="@dimen/_8sdp"
        app:cardCornerRadius="@dimen/_3sdp"
        app:cardElevation="@dimen/_4sdp">

        <TextView
            android:id="@+id/buyNow_field"
            android:layout_width="@dimen/_135sdp"
            android:layout_height="wrap_content"
            android:background="@drawable/bg_horizon_gradient"
            android:gravity="center"
            android:paddingBottom="@dimen/_10sdp"
            android:paddingTop="@dimen/_10sdp"
            android:text="BUY NOW"
            android:textColor="#fff"
            android:textSize="@dimen/_14ssp"
            android:textStyle="bold" />
    </android.support.v7.widget.CardView>
   </LinearLayout>
   </RelativeLayout>

I need like this but the below buttons are hiding

【问题讨论】:

    标签: android android-layout android-relativelayout


    【解决方案1】:
    <?xml version="1.0" encoding="utf-8"?>
    <android.support.v4.widget.DrawerLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/Drawer_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    
        <android.support.design.widget.CoordinatorLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true">
    
            <android.support.design.widget.AppBarLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                app:elevation="0dp">
    
                <android.support.v7.widget.Toolbar
                    android:id="@+id/Toolbar"
                    android:layout_width="match_parent"
                    android:layout_height="?actionBarSize" />
    
            </android.support.design.widget.AppBarLayout>
    
            <FrameLayout
                android:id="@+id/view_stub"
                android:layout_width="match_parent"
                android:layout_height="match_parent" >
                <RelativeLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_gravity="bottom"
                    android:gravity="center">
                    <LinearLayout
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:gravity="center">
                        <Button
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:gravity="center"
                            android:layout_gravity="center"/>
                    </LinearLayout>
                </RelativeLayout>
            </FrameLayout>
    
        </android.support.design.widget.CoordinatorLayout>
    
        <android.support.design.widget.NavigationView
            android:id="@+id/Navigation_view"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_gravity="start" />
    
    </android.support.v4.widget.DrawerLayout>
    

    【讨论】:

    • 实际上这是我使用的基本导航抽屉布局。在框架布局内,相应的布局将被膨胀
    • 尝试添加您遇到问题的布局代码
    • 您正在尝试将新布局膨胀到基本布局。为什么你没有在 xml 中定义
    • 我正在使用将用于所有活动的基本导航抽屉
    • 尝试移除按钮的卡片视图
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-21
    • 2015-10-04
    相关资源
    最近更新 更多