Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/184.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 将父项底部与下面的相对位置对齐_Android_Android Layout_Android Relativelayout - Fatal编程技术网

Android 将父项底部与下面的相对位置对齐

Android 将父项底部与下面的相对位置对齐,android,android-layout,android-relativelayout,Android,Android Layout,Android Relativelayout,您好。我有一组按钮,它们应该始终与底部对齐,但它们也都应该位于文本下方,它是这样的,如果文本较大,它只需按下滚动视图中的按钮,否则按钮应该与父底部对齐。问题是我将两个标记都添加到按钮的线性布局包装器中,但一旦我将文本的可见性设置为“消失”,视图就会弹出,而不会与父底部对齐,这是实际代码 <?xml version="1.0" encoding="utf-8"?> <ScrollView xmlns:android="http://schemas.android.com/apk/

您好。我有一组按钮,它们应该始终与底部对齐,但它们也都应该位于文本下方,它是这样的,如果文本较大,它只需按下滚动视图中的按钮,否则按钮应该与父底部对齐。问题是我将两个标记都添加到按钮的线性布局包装器中,但一旦我将文本的可见性设置为“消失”,视图就会弹出,而不会与父底部对齐,这是实际代码

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

谁能给点建议吗

编辑:视图的完整代码,实际按钮位于RelativeLayout中。在xml文件的底部有4个按钮。包装器是单产品按钮包装器

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


这是我第五次问stackoverflow问题,但根本没有答案,问题不是高等数学……stackoverflow发生了什么事?你4分钟前才提出这个问题。顺便说一句,你提到了scrollView。它在哪里。我发现xml具有相对性。但是我没有看到上面。这就是xml的外层吗?是的,让我完全更新它,以便您想要的是按钮保持在底部?我的回答如下。假设有一个相对的外部。是的,正确,这是我想要的,同时,按钮也总是在文本下面不幸的是,这是没有帮助的,但仍然很好的接近奇妙!!!工作得很有魅力!问题是重力,当我添加重力而不是对齐父底部时,所有操作都像tici taca!:)非常感谢。你救了我一天!明亮的