草庐IT

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

coder 2023-12-25 原文

美好的一天。我有一组按钮应该始终与底部对齐,但它们也都应该在文本下方,它是这样的,如果文本很大,它只会按下按钮在 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/

有关android - 将父底部与下面的 RelativeLayout Android 对齐的更多相关文章

  1. 安卓apk修改(Android反编译apk) - 2

    最近因为项目需要,需要将Android手机系统自带的某个系统软件反编译并更改里面某个资源,并重新打包,签名生成新的自定义的apk,下面我来介绍一下我的实现过程。APK修改,分为以下几步:反编译解包,修改,重打包,修改签名等步骤。安卓apk修改准备工作1.系统配置好JavaJDK环境变量2.需要root权限的手机(针对系统自带apk,其他软件免root)3.Auto-Sign签名工具4.apktool工具安卓apk修改开始反编译本文拿Android系统里面的Settings.apk做demo,具体如何将apk获取出来在此就不过多介绍了,直接进入主题:按键win+R输入cmd,打开命令窗口,并将路

  2. 电脑启动后显示器黑屏怎么办?排查下面4个问题,快速解决 - 2

    电脑启动出现显示器黑屏是一个相当常见的问题。如果您遇到了这个问题,不要惊慌,因为它有很多可能的原因,可以采取一些简单的措施来解决它。在本文中,小编将介绍下面4种常见的电脑启动后显示器黑屏的原因,排查这些原因,快速解决! 演示机型:联想Ideapad700-15ISK-ISE系统版本:Windows10一、显示器问题如果出现电脑启动后显示器黑屏的情况。那么首先您需要检查一下显示器是否正常工作。您可以通过更换另一个显示器或将当前显示器连接到另一台计算机来检查显示器是否存在问题。如果问题仍然存在,那么您可以排除显示器故障的可能性。 二、显卡问题如果您的电脑配备了独立显卡,那么显卡故障也可能是导致电脑

  3. ruby-on-rails - 在页面的最底部包含 javascript 文件 - 2

    我有一个Rails应用程序。还有一个javascript(javascript1.js)文件必须包含在每个View的最底部。我把它放在/assets/javascripts文件夹中。Application.js包含以下代码//=requirejquery//=requirejquery_ujs//=someotherfiles//=require_directory.即使Application.js中不包含javascript1.js,它也会自动包含,不是吗?那么我怎样才能做我想做的事呢? 最佳答案 单独定义、包含和执行您的java

  4. 微信小程序顶部标题栏与胶囊对齐 - 2

    介绍    最近在做微信小程序时,顶部标题栏总是与胶囊对不齐。往往是在这款手机上对齐了,在另外一款手机差很多。我在查阅资料后,提出了一种方法解决这个问题,即:在页面onLoad或组件created时,利用微信小程序提供的API,获取系统状态栏高度和胶囊信息,进而动态调整顶部标题栏样式。在苹果、小米、荣耀手机做验证,能做到精准对齐。理论        胶囊样式应该是垂直居中,有1px的border,border-radius为18px。        若要使顶部标题栏与胶囊对齐,则其高度必须是导航栏高度,标题栏内容也要垂直居中,顶部标题栏的外边距或内边距必须是状态栏高度。        如果顶部

  5. ruby - Prawn :有没有办法让一个盒子里的所有内容垂直对齐? - 2

    我正在尝试将一些内容垂直居中放置在bounding_box中。对于单个文本,这没问题:bounding_box([0,bounds.top],:width=>pdf.bounds.right,:height=>pdf.bounds.top)dotext"verticallyalignedinthesurroundingbox",:valign=>:centerend但是如果我的边界框中有多个元素,我该怎么办:bounding_box([0,bounds.top],:width=>pdf.bounds.right,:height=>pdf.bounds.top)dotext"vertic

  6. Android Studio开发之使用内容组件Content获取通讯信息讲解及实战(附源码 包括添加手机联系人和发短信) - 2

    运行有问题或需要源码请点赞关注收藏后评论区留言一、利用ContentResolver读写联系人在实际开发中,普通App很少会开放数据接口给其他应用访问。内容组件能够派上用场的情况往往是App想要访问系统应用的通讯数据,比如查看联系人,短信,通话记录等等,以及对这些通讯数据及逆行增删改查。首先要给AndroidMaifest.xml中添加响应的权限配置 下面是往手机通讯录添加联系人信息的例子效果如下分成三个步骤先查出联系人的基本信息,然后查询联系人号码,再查询联系人邮箱代码 ContactAddActivity类packagecom.example.chapter07;importandroid

  7. Android 10.0 设置默认launcher后安装另外launcher后默认Launcher失效的功能修复 - 2

    1.前言 在10.0的系统rom定制化开发中,在系统中有多个launcher的时候,会在开机进入launcher的时候弹窗launcher列表,让用户选择进入哪个launcher,这样显得特别的不方便所以产品开发中,要求用RoleManager的相关api来设置默认Launcher,但是在设置完默认Launcher以后,在安装一款Launcher的时候,默认Launcher就会失效,在系统设置的默认应用中Launcher选项就为空,点击home键的时候会弹出默认Launcher列表,让选择进入哪个默认Launcher.所以需要从安装Launcher的流程来分析相关的设置。来解决问题设置默认La

  8. AiBote 2022 新研发的自动化框架,支持 Android 和 Windows 系统。速度非常快 - 2

    Ai-Bot基于流行的Node.js和JavaScript语言的一款新自动化框架,支持Windows和Android自动化。1、Windowsxpath元素定位算法支持支持Windows应用、.NET、WPF、Qt、Java和Electron客户端程序和ie、edgechrome浏览器2、Android支持原生APP和H5界面,元素定位速度是appium十倍,无线远程自动化操作多台安卓设备3、基于opencv图色算法,支持找图和多点找色,1080*2340全分辨率找图50MS以内4、内置免费OCR人工智能技术,无限制获取图片文字和找字功能。5、框架协议开源,除官方node.jsSDK外,用户可

  9. Android Gradle 7.1+新版本依赖变化 - 2

    前一段时间由于工作需要把可爱的小雪狐舍弃了,找到了小蜜蜂。但是新版本的小蜜蜂出现了很多和旧版本不一样的位置。1.功能位置迁移,原来在工程build.gradle的buildscript和allprojects移动至setting.gradle并改名为pluginManagement和dependencyResolutionManagement。里面的东西依旧可以按照原来的copy过来。pluginManagement{repositories{gradlePluginPortal()google()mavenCentral()}}dependencyResolutionManagement{r

  10. ruby - Ruboto 的最佳教程(适用于 Android 的 ruby​​)? - 2

    关闭。这个问题不符合StackOverflowguidelines.它目前不接受答案。要求我们推荐或查找工具、库或最喜欢的场外资源的问题对于StackOverflow来说是偏离主题的,因为它们往往会吸引自以为是的答案和垃圾邮件。相反,describetheproblem以及迄今为止为解决该问题所做的工作。关闭9年前。Improvethisquestion我几乎用完了Ruby,但现在想试试Ruboto,android上的ruby​​。谷歌未能给我足够的(几乎没有结果)。所以任何人都可以分享一些关于Ruboto的教程。

随机推荐