簡體   English   中英

將父母底部與RelativeLayout Android下方對齊

[英]Align Parent Bottom With Below RelativeLayout Android

美好的一天。我有一組按鈕,它們應該始終與底部對齊,但它們也應該在文本下面,它就像這樣,如果文本很大,它只是按下滾動視圖內的按鈕,否則按鈕應該與父底部對齊。問題是我將兩個標簽添加到按鈕的線性布局包裝中,但是一旦我將文本的可見性設置為消失,視圖就會彈出而不是對齊到父底部,這是實際的代碼,

<?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="$12.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個按鈕。包裝器是single_product_buttons_wrapper

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

嘗試這個:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM