使用 TextInputLayout 和 Spinner 的对齐问题

2024-03-11

我遇到了 TextInputLayout 和 Spinner 的对齐问题,我希望 Spinner 下划线与 TextInputLayout 内的 EditText 下划线对齐。这就是我正在做的:

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:gravity="bottom">

    <android.support.design.widget.TextInputLayout
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1">

        <EditText
            android:id="@+id/txt_discipline_code"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="@string/lbl_input_discipline_code"/>
    </android.support.design.widget.TextInputLayout>

    <Spinner
        android:id="@+id/spnnr_color_discipline_register"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        style="@style/Base.Widget.AppCompat.Spinner.Underlined">

    </Spinner>
</LinearLayout>

但 Spinner 是一个下面一点点 https://i.stack.imgur.com/QazJE.png。有人可以帮助我吗?提前致谢。

EDIT:

Here is what I want: The Y underline of the EditText equal to the Y underline of the Spinner

我将 Spinner layout_marginBottom 设置为 1.5dp 达到此对齐方式:

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:gravity="bottom">

    <android.support.design.widget.TextInputLayout
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1">

        <EditText
            android:id="@+id/txt_discipline_code"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="Code"/>
    </android.support.design.widget.TextInputLayout>

    <Spinner
        android:id="@+id/spnnr_color_discipline_register"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        style="@style/Base.Widget.AppCompat.Spinner.Underlined"
        android:layout_marginBottom="1.5dp">

    </Spinner>
</LinearLayout>

但恐怕这在其他尺寸不同的设备上无法正常工作。这是唯一的解决方案吗?


根据你提到的,你想达到这个结果:

使用此代码:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:gravity="bottom"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:baselineAligned="false">

    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1">

        <ImageView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:srcCompat="@drawable/ic_launcher"
            android:id="@+id/imageView"
            android:padding="10dp"
            android:layout_weight="5" />

        <android.support.design.widget.TextInputLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1">
            <EditText
                android:id="@+id/name_text"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="0.5"
                android:hint="Name"/>
        </android.support.design.widget.TextInputLayout>
    </LinearLayout>

    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1">

        <ImageView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:srcCompat="@drawable/ic_launcher"
            android:id="@+id/imageView1"
            android:padding="10dp"

            android:layout_weight="1.1" />

        <android.support.design.widget.TextInputLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="-12dp"
            android:layout_marginStart="-12dp"
            android:layout_weight="0.6">
            <EditText
                android:id="@+id/code_text"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"

                android:hint="Code"/>
        </android.support.design.widget.TextInputLayout>

        <Spinner
            android:id="@+id/spnnr_color_discipline_register"
            android:layout_width="match_parent"
            android:layout_weight="1"
            android:layout_height="wrap_content"/>
    </LinearLayout>

    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1">

        <ImageView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:srcCompat="@drawable/ic_launcher"
            android:id="@+id/imageView2"
            android:padding="10dp"
            android:layout_weight="5" />

        <android.support.design.widget.TextInputLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1">
            <EditText
                android:id="@+id/foo_text"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="0.5"
                android:hint="Foo"/>
        </android.support.design.widget.TextInputLayout>
    </LinearLayout>


</LinearLayout>

希望能帮助到你!!!

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

使用 TextInputLayout 和 Spinner 的对齐问题 的相关文章

  • 在应用程序简历中隐藏软键盘

    我有一个 Android 应用程序 使用 Xamarin 用 C 编写 我已将应用程序简化为包含 TextView 和用于横幅广告的 Google admod AdView 的 LinearLayout 我不希望软键盘出现在应用程序中 这不
  • Android 通知进度条冻结

    这是我正在使用的代码 http pastebin com 3bMCKURu http pastebin com 3bMCKURu 问题是 一段时间后 文件变得更重 通知栏下拉速度变慢 最后它就冻结了 你的通知太频繁了 这就是它冻结的原因 让
  • getItem 与 getItemAtPosition

    有两种方法可以获取列表视图中的选定项目 list getAdapter getItem position list getItemAtPosition position 我的问题是 哪一种是首选的做法 我见过人们同时使用这两种方法 您可以使
  • 导航组件重复 NavArgs 的问题

    我有一个片段 class SomeFragment private val args by navArgs
  • 与 Admob 广告单元 ID 混淆

    我跟着tutorial https developers google com admob android quick start在我的应用程序中创建广告横幅 到目前为止 这有效 我可以看到测试广告 但是 本教程指示我在两个不同的位置使用两
  • 如何更新 Firebase 中的节点密钥?

    如何重命名14 04 2017 node 没有用于重命名节点的 API 您必须获取节点的值 使用新名称将其保存到数据库并删除旧节点
  • Firebase Analytics 禁用受众国家/地区跟踪

    我正在开发一个严格不允许位置跟踪的应用程序 我想使用 Firebase Analytic 的其他功能 例如 PageTransitions 和 Crashalitics 但如果我无法禁用受众位置跟踪 我就无法使用其中任何功能 这是我在 An
  • 共同的偏好不断消失

    我正在使用共享首选项来存储我的应用程序的登录凭据 除了一个用户之外 一切正常 一段时间后 共享偏好似乎会以某种方式重置或清除 我已针对该用户调整了我的应用程序 使其不再清除他的共享偏好设置 这样我就可以确定这不是我的应用程序的错 但即使在这
  • Delphi XE7 Android 全屏(隐藏软键)

    如何在XE7中全屏显示 隐藏顶部 标题 和底部 软键 工具栏 在 XE6 中 我可以通过在应用程序部分写入来调整 AndroidManifest 以使我的应用程序全屏显示并且没有操作栏 android theme android style
  • 更新到材质 1.2.0 后,材质按钮上缺少圆角半径属性

    这是我的材质按钮代码
  • 从 Firebase 数据库填充微调器

    public class MainActivity extends AppCompatActivity DatabaseReference reference Spinner areaSpinner ArrayList
  • minHeight 有什么作用吗?

    在附图中 我希望按钮列与图像的高度相匹配 但我也希望按钮列有一个最小高度 它正确匹配图像的高度 但不遵守 minHeight 并且会使按钮向下滑动 我正在为按钮列设置这些属性
  • 从 android 简单上传到 S3

    我在网上搜索了从 android 上传简单文件到 s3 的方法 但找不到任何有效的方法 我认为这是因为缺乏具体步骤 1 https mobile awsblog com post Tx1V588RKX5XPQB TransferManage
  • Android Webview 图像未加载

    我制作了一个简单的应用程序WebView 但有些图片无法加载 正确 在我的电脑上 错误 在模拟器中 Correct 错误 没有横幅 于是我用Chrome debug进行调试 发现我的代码被改变了 我不添加像noscript or style
  • 材质设计图标颜色

    应该是哪种颜色 暗 材质图标 在官方文档上 https www google com design spec style icons html icons system icons https www google com design s
  • 调节麦克风录音音量

    我们正在尝试调整录音时的音量级别 麦克风似乎非常敏感 会接收到很多静电 我们查看了 setVolumeControlStream 但找不到传入其中来控制麦克风的流 将您的音频源设置为 MIC using MediaRecorder Audi
  • 当手机旋转(方向改变)时如何最好地重新创建标记/折线

    背景 开发一个使用 Android Google Map v2 的本机 Android 应用程序 使用android support v4 app FragmentActivity 在 Android v2 2 上运行 客观的 在更改手机方
  • SharedFlow 和 StateFlow 的主要区别

    两者有什么区别共享流 and 状态流 以及如何使用这些MVI建筑学 使用简单更好吗Flow或者这些作为状态和事件 Flow 是冷的 意味着它仅在收集数据时才发出数据 另外Flow不能保存数据 可以把它看成是水在里面流动的管道 Flow中的数
  • 用于推送通知的设备令牌

    我正在实施推送通知服务 我需要创建一个数据库来存储 4 个移动平台的所有设备令牌 我想根据他们的平台 iOS Android BlackBerry WP7 来组织它们 但是有什么方法可以区分平台 这样如果我只想向 Android 用户发送消
  • 无法将 admob 与 firebase iOS/Android 项目链接

    我有两个帐户 A 和 B A 是在 Firebase 上托管 iOS Android unity 手机游戏的主帐户 B 用于将 admob 集成到 iOS Android 手机游戏中 我在尝试将 admob 分析链接到 Firebase 项

随机推荐

  • 干扰器 helloworld 示例

    我想学习颠覆者框架 http code google com p disruptor 谁能给我一个用Java语言在main方法中运行的helloworld例子 这是一个简单的 可运行的示例 说明如何使用 Disruptor 库 示例是使用
  • 卸载 oh-my-zsh 时遇到问题?

    我在 OSX 上 想要切换回原来的 zsh 配置哦我的zsh http github com robbyrussell oh my zsh 但是当我运行uninstall脚本它给了我一个错误 sudo uninstall oh my zsh
  • dxDataGrid - 如何刷新小部件

    当我单击按钮时 刷新不起作用 如果目的是添加到数据库按钮 请按按钮进入屏幕 但就是不更新 我用ajax创建了一个数据网格 我也在ViewModel中写了刷新功能 不刷新可能是什么原因 我的数据是json ajax type GET url
  • 如何使用python中的lambda函数在通过S3连接的AWS athena中进行查询

    我将 csv 文件保存在 S3 存储桶中 我可以使用AWS Athena查询S3的数据 有什么方法可以将 lambda 函数连接到 athena 并从 lambda 函数查询数据 请帮忙 Thanks 正如 Chris Pollard 所说
  • 如何捕捉Tk中的最大化信号?

    您可以通过以下方式将命令与窗口的 X 按钮绑定 wm protocol windowPath WM DELETE WINDOW command 如何对窗口的最大化按钮执行相同的操作 X11 中也没有标准协议ICCCM套 http tronc
  • HTML 选择选项文本等宽

    我正在尝试选择使用等宽字体的选项 以便当您单击下拉菜单时它们会垂直排列 我试图将代码左对齐 后跟破折号 然后是描述 我使用编码空格添加了选项 以便每个选项在破折号之前具有相同数量的字符 但它们仍然没有对齐 我尝试了新的快递和等宽字体 我可以
  • php中相应的嵌套三元运算符? [复制]

    这个问题在这里已经有答案了 我想转换以下if else condition to nested ternary操作员 if projectURL echo projectURL elseif project project url echo
  • 如何知道php邮件发送失败

    我正在从 php mail 发送邮件 如果发送到目的地失败 我希望收到失败消息 to email protected cdn cgi l email protection email from email protected cdn cgi
  • net::ERR_ABORTED 429 仅通过本地主机使用 ipinfo.io

    我想从前端设备获取 IP 地址 我发现this https ipinfo io developers名为 IPINFO io 的免费 API 根据使用 Jquery 获取 IP 地址的文档 我需要做的就是 get https ipinfo
  • 如何在网络驱动程序中检查页面是否已完全加载?

    我正在编写一些 Java Webdriver 代码来自动化我的应用程序 如何正确判断页面是否已加载 该应用程序也有一些 Ajax 调用 我已经声明了对 WebDriver 的隐式等待 硒会为你做到这一点 或者至少它尽力了 有时它会达不到要求
  • 使用 sse 内在函数时如何打破循环?

    m128 pSrc1 m128 string m128 m0 mm set ps1 0 null character while 1 m128 result m128 mm cmpeq ss pSrc1 m0 if character is
  • 子菜单未完全并排定位

    我发现了一个问题 sub menu code left and transform translateX 所以我将位置更改为相对位置并使用上面的两个代码重新定位 它似乎有效 但现在我拥有的两个子菜单不再并排 他们所做的只是相距几厘米顶部 不
  • 为什么我的 NSMutableDictionary 为零?

    我正在尝试将数组存储在 NSMutableDictionary 中 但是 在我为其设置对象后 NSMutableDictionary 为空 这是我的代码 感谢任何帮助 NSMutableArray arrTemp NSMutableArra
  • 验证电子邮件地址

    我正在尝试使用以下代码使用 C 发送电子邮件 MailMessage mail new MailMessage mail From new MailAddress fromAddress friendlyName mail To Add t
  • 抽象类的shared_ptr向量到副本向量

    我有一个带有共享指针的向量 std vector
  • 将 MVC 与 JavaFx 一起应用

    我是 GUI 世界 OO 设计模式的新手 我想在我的 GUI 应用程序中使用 MVC 模式 我已经阅读了一些关于 MVC 模式的教程 模型将包含数据 视图将包含视觉元素和控制器将连接视图和模型 我有一个包含 ListView 节点的视图 并
  • std::is_constructible 在具有非公共析构函数的类型上

    预期结果是什么std is constructible http en cppreference com w cpp types is constructible在具有私有或受保护析构函数的类型上 例如 我仍然可以在堆上构造这样的对象 即使
  • 将文件从一个目录复制到另一个目录

    我对 C 很陌生 我正在尝试让我的程序将文件从一个位置复制到另一个位置 我的方法如下 private void CopyInstallFiles object sender EventArgs e string sourceFile F i
  • HTML 表单验证 - 基于单选按钮选择的条件[重复]

    这个问题在这里已经有答案了 我有一个 HTML 表单 并且正在使用 JQuery Validate 插件来要求某些表单字段为必填字段 我有一个带有 3 个选项的单选按钮字段 小时 天 不确定 另一个字段用于输入与小时或天选择相对应的数字 但
  • 使用 TextInputLayout 和 Spinner 的对齐问题

    我遇到了 TextInputLayout 和 Spinner 的对齐问题 我希望 Spinner 下划线与 TextInputLayout 内的 EditText 下划线对齐 这就是我正在做的