Android-AlignParentBottom占据了所有可用空间

苛刻的阿什拉

我正在尝试button在布局的底部对齐a 但是问题在于,每当我使用layout_alignParentBottom="true"时,它都会占用所有可用空间,如下面的快照所示。

在此处输入图片说明

这是XML代码

    <?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="@drawable/ic_transparent"
    android:orientation="vertical"
    android:padding="5dp"
    android:theme="@style/Theme.MaterialComponents.DayNight"
    tools:context=".Activities.DisplayProductDetails">


    <ImageView
        android:id="@+id/display_ProductImage"
        android:layout_width="match_parent"
        android:layout_height="300dp"
        android:scaleType="centerCrop" />

    <com.google.android.material.card.MaterialCardView
        android:id="@+id/material"
        android:layout_below="@+id/display_ProductImage"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="20dp"
        android:background="@drawable/ic_rectangle"
        android:padding="20dp"
        android:rotationX="20"
        app:cardCornerRadius="20dp"
        android:layout_centerHorizontal="true">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            >

            <TextView
                android:id="@+id/display_ProductName"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerHorizontal="true"
                android:layout_marginTop="10dp"
                android:fontFamily="@font/raleway"
                android:gravity="center"
                android:padding="10dp"
                android:text="@string/product_name"
                android:textColor="#eee"
                android:textSize="22sp" />

            <TextView
                android:id="@+id/display_ProductDesc"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@id/display_ProductName"
                android:layout_centerHorizontal="true"
                android:layout_marginTop="5dp"
                android:gravity="center"
                android:padding="10dp"
                android:text="@string/product_description"
                android:textColor="#eee"
                android:textSize="18sp" />

            <TextView
                android:id="@+id/display_ProductPrice"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@+id/display_ProductDesc"
                android:layout_centerHorizontal="true"
                android:layout_marginTop="5dp"
                android:layout_marginBottom="15dp"
                android:gravity="center"
                android:padding="10dp"
                android:text="@string/product_price"
                android:textColor="#eee"
                android:textSize="18sp" />

            <com.cepheuen.elegantnumberbutton.view.ElegantNumberButton
                android:id="@+id/enb"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@+id/display_ProductPrice"
                android:layout_centerHorizontal="true"
                android:layout_marginBottom="10dp"
                android:gravity="center"
                app:backGroundColor="@color/buttonColor"
                app:finalNumber="50"
                app:initialNumber="1"
                app:textColor="#eee" />


        </RelativeLayout>
    </com.google.android.material.card.MaterialCardView>


    <Button
        android:id="@+id/display_AddtoCart"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="20dp"
        android:layout_below="@+id/material"
        android:layout_alignParentBottom="true"
        android:background="@color/buttonColor"
        android:fontFamily="@font/raleway"
        android:gravity="center"
        android:text="@string/add_to_cart"
        android:textColor="#eee"
        android:textSize="20sp" />

</RelativeLayout>
快感

这条线导致的顶边Button与的底边对齐MaterialCardView

android:layout_below="@+id/material"

这条线导致的Button底边与父底边对齐

android:layout_alignParentBottom="true"

layout_height="wrap_content"据我所知,在这种情况下不会考虑/计算,甚至可能是0px。所以一切看起来都像是用XML设计的...

如果您想将底部的按钮对齐,则只需使用layout_alignParentBottom="true"并移除layout_below="@+id/material"(无论如何它都会在下面)

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

托管viewPager的Android FrameLayout占用所有可用空间

Android-如何在工具栏中设置项目以填充所有可用空间?

Android-没有可用空间

Android GridLayout单个CardView占据所有屏幕

我怎样才能使pageView.Builder在Flutter中占据所有可用空间?

如何使div占据所有可用高度?

React:使div占据所有可用高度

css 列占据所有剩余空间

如何在不指定div宽度的情况下使div占据所有可用的剩余水平空间?

谷歌 API GPS 位置 Android 可用于所有活动

Android:如何从手机获取所有可用的日历

Android Studio中可用的所有评论标签是什么?

如何使ListView的项目占据所有可用高度?

如何设置权重以使底视图占据Android的剩余空间

如何使textView1占据所有其他空间?

如何使此菜单占据所有剩余空间的宽度?

如何使Polymer元素占据页面上的所有垂直空间?

卡片在颤动中占据了所有垂直空间

弯曲孩子的孩子占据了所有的空间

EditText如何占据布局中的所有剩余空间?

在android全屏模式下使用所有空间

Android XML布局-ImageView占用所有空间

Android:具有layout_alignParentBottom的RelativeLayout translationY动画

使编辑文本适合可用空间Android

使div扩展以占用所有可用空间

如何使有角度的材料卡占据可用的垂直空间并使其内容可滚动

Android:为什么计算出的可用空间与Android显示的可用空间不同

文本占据了设备的所有空间,没有任何底边

如何使用Android的本机网络服务发现来查找所有可用服务