Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Align Parent Bottom With Below RelativeLayout Android

Good day.I have an set of buttons which should be aligned to the bottom always,but they all also should be below an text,and it goes like this,if text is large,it is going just to push the buttons inside the scrollview,otherwise the buttons should be aligned to the parent bottom.Issue is that i add both of the tags to the linear layout wrapper of the buttons,but as soon as i set visibility of text to gone,the view just pops up and not aligning to parent bottom,here is the actual code,

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

Can anyone please give any suggestion?

Edit : The full code of the view,actual buttons are inside RelativeLayout at the bottom of xml files there are 4 of buttons.The wrapper is single_product_buttons_wrapper

like image 332
Android Developer Avatar asked Dec 03 '22 23:12

Android Developer


1 Answers

Add android:gravity="bottom" to LinearLayout containing buttons. It will work have tested it.

<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">
like image 111
Jitendra Avatar answered Jan 28 '23 06:01

Jitendra