将父底部与下方 RelativeLayout 对齐 Android

Align Parent Bottom With Below RelativeLayout Android

很好 day.I 有一组按钮应该始终对齐到底部,但它们也都应该在文本下方,它是这样的,如果文本很大,它只是在滚动视图中按下按钮,否则按钮应该与父级对齐 bottom.Issue 是我将这两个标签都添加到按钮的线性布局包装器中,但是一旦我将文本的可见性设置为消失,视图只是弹出而不是对齐父底部,这是实际代码,

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/single_product_scroll_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true">

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

        <ImageView
            android:id="@+id/single_product_image"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="35dp"
            android:src="@drawable/img_placeholder" />

        <RelativeLayout
            android:id="@+id/basket_layout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_above="@+id/single_product_divider"
            android:layout_alignEnd="@+id/single_product_divider"
            android:layout_alignLeft="@+id/single_product_divider"
            android:layout_alignParentTop="true"
            android:layout_alignRight="@+id/single_product_divider"
            android:layout_alignStart="@+id/single_product_divider"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="10dp"
            android:visibility="gone">

            <ImageView
                android:id="@+id/basket_success_icon"
                android:layout_width="46dp"
                android:layout_height="46dp"
                android:layout_centerVertical="true"
                android:layout_marginLeft="26dp"
                android:src="@drawable/success_icon" />

            <TextView
                android:id="@+id/basket_product_name"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignTop="@+id/basket_success_icon"
                android:layout_marginLeft="16dp"
                android:layout_marginTop="5dp"
                android:layout_toRightOf="@+id/basket_success_icon"
                android:text="@string/product_added_to_basket_text"
                android:textColor="#ffffff"
                android:textSize="16sp" />

        </RelativeLayout>

        <View
            android:id="@+id/single_product_divider"
            android:layout_width="match_parent"
            android:layout_height="1dp"
            android:layout_below="@+id/single_product_image"
            android:layout_margin="25dp"
            android:background="#D1D3D4">

        </View>

        <TextView
            android:id="@+id/single_product_name"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignLeft="@+id/single_product_divider"
            android:layout_alignStart="@+id/single_product_divider"
            android:layout_below="@+id/single_product_divider"
            android:text="@string/loading_text"
            android:textColor="#231F20" />

        <TextView
            android:id="@+id/single_product_weight_and_servings"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignLeft="@+id/single_product_divider"
            android:layout_alignStart="@+id/single_product_divider"
            android:layout_below="@+id/single_product_name"
            android:layout_marginTop="5dp"
            android:text="@string/weight_and_servings_text"
            android:textColor="#231F20" />

        <TextView
            android:id="@+id/single_product_price"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignLeft="@+id/single_product_weight_and_servings"
            android:layout_alignStart="@+id/single_product_weight_and_servings"
            android:layout_below="@+id/single_product_weight_and_servings"
            android:layout_marginTop="15dp"
            android:text=".09"
            android:textColor="#009444"
            android:textSize="17sp"
            android:textStyle="bold" />

        <RatingBar
            android:id="@+id/single_product_rating"
            style="@style/Base.Widget.AppCompat.RatingBar.Small"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignLeft="@+id/single_product_price"
            android:layout_alignStart="@+id/single_product_price"
            android:layout_below="@+id/single_product_price"
            android:layout_marginTop="5dp"
            android:numStars="5" />

        <TextView
            android:id="@+id/single_product_rating_text"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignTop="@+id/single_product_rating"
            android:layout_marginLeft="5dp"
            android:layout_toRightOf="@+id/single_product_rating"
            android:text="10.0/10"
            android:textColor="#231F20"
            android:textSize="12sp" />

        <TextView
            android:id="@+id/single_product_review_count"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignTop="@+id/single_product_rating_text"
            android:layout_marginLeft="5dp"
            android:layout_toRightOf="@+id/single_product_rating_text"
            android:text="8 reviews"
            android:textColor="#EC2027"
            android:textSize="12sp" />

        <TextView
            android:id="@+id/single_product_stock_status"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_alignTop="@+id/single_product_review_count"
            android:layout_marginRight="10dp"
            android:text="In stock"
            android:textColor="#939598" />

        <View
            android:id="@+id/single_product_center_divider"
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:layout_below="@+id/single_product_rating"
            android:layout_centerHorizontal="true"></View>


        <Spinner
            android:id="@+id/single_product_weight_spinner"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:layout_alignParentLeft="true"
            android:layout_below="@+id/single_product_rating"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="2dp"
            android:layout_marginTop="10dp"
            android:layout_toLeftOf="@+id/single_product_center_divider"
            android:background="@drawable/spinner_background"
            android:spinnerMode="dropdown"></Spinner>

        <Spinner
            android:id="@+id/single_product_type_spinner"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:layout_alignParentRight="true"
            android:layout_below="@+id/single_product_rating"
            android:layout_marginLeft="2dp"
            android:layout_marginRight="10dp"
            android:layout_marginTop="10dp"
            android:layout_toRightOf="@+id/single_product_center_divider"
            android:background="@drawable/spinner_background"
            android:spinnerMode="dropdown"></Spinner>

        <TextView
            android:id="@+id/single_product_description"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/single_product_type_spinner"
            android:layout_margin="16dp"
            android:text="This is simply the best tripod for the money you\'ll ever buy,it\'s rock solid and the head alone is worth more then the asking price"
            android:textColor="#231F20" />

        <RelativeLayout
            android:id="@+id/single_product_buttons_wrapper"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_below="@+id/single_product_description"
            android:orientation="vertical">


            <Button
                android:id="@+id/single_product_add_to_cart_button"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="5dp"
                android:layout_marginRight="5dp"
                android:background="#F26522"
                android:text="@string/add_to_cart_text"
                android:textAllCaps="false"
                android:textColor="#ffffff" />


            <Button
                android:id="@+id/single_product_info_button"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/single_product_add_to_cart_button"
                android:layout_marginLeft="6dp"
                android:layout_marginRight="5dp"
                android:layout_marginTop="8dp"
                android:background="#E7E8E9"
                android:drawableRight="@drawable/ic_arrow_down"
                android:paddingRight="10dp"
                android:text="@string/product_info_text"
                android:textAllCaps="false"
                android:textColor="#231F20" />

            <Button
                android:id="@+id/single_product_nutritional_info_button"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/single_product_info_button"
                android:layout_marginLeft="6dp"
                android:layout_marginRight="5dp"
                android:layout_marginTop="8dp"
                android:background="#E7E8E9"
                android:drawableRight="@drawable/ic_arrow_down"
                android:paddingRight="10dp"
                android:text="@string/product_nutritional_text"
                android:textAllCaps="false"
                android:textColor="#231F20" />

            <Button
                android:id="@+id/single_product_reviews_button"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/single_product_nutritional_info_button"
                android:layout_marginBottom="5dp"
                android:layout_marginLeft="6dp"
                android:layout_marginRight="5dp"
                android:layout_marginTop="8dp"
                android:background="#E7E8E9"
                android:drawableRight="@drawable/ic_arrow_down"
                android:paddingRight="10dp"
                android:text="@string/product_reviews_text"
                android:textAllCaps="false"
                android:textColor="#231F20" />
        </RelativeLayout>
    </RelativeLayout>
</ScrollView>

谁能给点建议吗?

编辑:视图的完整代码,实际按钮在 xml 文件底部的 RelativeLayout 里面有 4 个 buttons.The 包装器是 single_product_buttons_wrapper

试试这个:

<?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"
    android:focusable="true"
    android:focusableInTouchMode="true">

    <TextView
        android:id="@+id/single_product_description"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="16dp"
        android:text="This is simply the best tripod for the money you\'ll ever buy,it\'s rock solid and the head alone is worth more then the asking price"
        android:textColor="#231F20" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:orientation="vertical">


        <Button
            android:id="@+id/single_product_add_to_cart_button"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_above="@+id/single_product_info_button"
            android:layout_marginLeft="5dp"
            android:layout_marginRight="5dp"
            android:background="#F26522"
            android:text="123"
            android:textAllCaps="false"
            android:textColor="#ffffff" />


        <Button
            android:id="@+id/single_product_info_button"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_above="@+id/single_product_nutritional_info_button"
            android:layout_marginLeft="6dp"
            android:layout_marginRight="5dp"
            android:layout_marginTop="8dp"
            android:background="#E7E8E9"

            android:paddingRight="10dp"
            android:text="234"
            android:textAllCaps="false"
            android:textColor="#231F20" />

        <Button
            android:id="@+id/single_product_nutritional_info_button"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_above="@+id/single_product_reviews_button"
            android:layout_marginLeft="6dp"
            android:layout_marginRight="5dp"
            android:layout_marginTop="8dp"
            android:background="#E7E8E9"
            android:paddingRight="10dp"
            android:text="5555"
            android:textAllCaps="false"
            android:textColor="#231F20" />

        <Button
            android:id="@+id/single_product_reviews_button"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_marginBottom="5dp"
            android:layout_marginLeft="6dp"
            android:layout_marginRight="5dp"
            android:layout_marginTop="8dp"
            android:background="#E7E8E9"
            android:paddingRight="10dp"
            android:text="99999"
            android:textAllCaps="false"
            android:textColor="#231F20" />
    </LinearLayout>


</RelativeLayout>

android:gravity="bottom" 添加到包含按钮的 LinearLayout。它会工作已经测试过了。

<LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_below="@+id/single_product_description"
        android:gravity="bottom"
        android:orientation="vertical">