gpt4 book ai didi

android - 将父底部与下面的 RelativeLayout Android 对齐

转载 作者:太空宇宙 更新时间:2023-11-03 11:32:54 25 4
gpt4 key购买 nike

美好的一天。我有一组按钮应该始终与底部对齐,但它们也都应该在文本下方,它是这样的,如果文本很大,它只会按下按钮在 ScrollView 中,否则按钮应与父底部对齐。问题是我将这两个标签都添加到按钮的线性布局包装器中,但是一旦我将文本的可见性设置为消失, View 就会弹出并且不与父底部对齐,这是实际代码,

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

谁能给点建议?

编辑: View 的完整代码,实际按钮在 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">

关于android - 将父底部与下面的 RelativeLayout Android 对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39138434/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com