使用 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 中保存相机的临时照片?

    在尝试从相机拍照并将其保存到应用程序的缓存文件夹中时 我没有得到任何可见的结果 应用程序不会崩溃 但在 LogCat 上 当我尝试将 ImageView src 字段设置为刚刚获取的文件的 URI 时 我收到此消息 09 17 14 03
  • 在包“android”中找不到属性“backgroundTint”的资源标识符

    我发现了一些视图 xml 属性 例如backgroundTint backgroundTintMode 但是当我使用它作为视图属性定义时 Eclipse 显示错误 No resource identifier found for attri
  • React Native 从 JavaScript 代码内部访问 strings.xml

    有没有办法访问当前值android app src main res values strings xml从 JavaScript 代码内部 我想为每个构建放置不同的端点 URL 但我什至无法检测到反应本机代码内的构建类型 而不必求助于 D
  • Sqlite数据库生命周期?关闭应用程序后它会被删除吗?

    我正在遵循一个简单的教程 该教程创建一个从 SQLiteOpenHelper 扩展的类 并创建一个包含一个表和 5 行的数据库 好的 但我需要更多地了解 android Sqlite 数据库 例如 如果应用程序关闭或手机关机会发生什么 数据
  • 找不到 com.google.firebase:firebase-core:9.0.0 [重复]

    这个问题在这里已经有答案了 在遵循有些不一致的指示之后here https firebase google com docs admob android quick start name your project and here http
  • Android 后退按钮无法与 Flutter 选项卡内的导航器配合使用

    我需要在每个选项卡内有一个导航器 因此当我推送新的小部件时 选项卡栏会保留在屏幕上 代码运行得很好 但是 android 后退按钮正在关闭应用程序而不是运行 Navigator pop import package flutter mate
  • CardView 圆角获得意想不到的白色

    When using rounded corner in CardView shows a white border in rounded area which is mostly visible in dark environment F
  • 在画布上绘图

    我正在编写一个 Android 应用程序 它可以在视图的 onDraw 事件上直接绘制到画布上 我正在绘制一些涉及单独绘制每个像素的东西 为此我使用类似的东西 for int x 0 x lt xMax x for int y 0 y lt
  • Android 模拟器插件无法初始化后端 EGL 显示

    我在 Cloudbees 上设置了 Jenkins 作业 并且可以在那里成功签出并编译我的 Android 项目 现在我想在 android 模拟器中运行一些 JUnit 测试并添加 Android 模拟器插件 我将 显示模拟器窗口 选项设
  • CollapsingToolBarLayout - 状态栏稀松布颜色不改变

    几天前我更新了我的 android studio 并开始使用 CoordinatorLayout 和 CollapsingToolbarLayout 只是尝试一些东西 工具栏稀松布颜色似乎覆盖了状态栏初始颜色和状态栏稀松布颜色 从 xml
  • Android SIP 来电使用带有广播接收器的服务

    大家好 其实我正在尝试创建一个应用程序 支持基于 SIP 通过互联网进行音频呼叫 这里使用本机 sip 我遇到了来电问题 我已经完成了服务的注册部分 但是在接听电话时我无法接听电话 请帮助我 Service file package exa
  • 原色(有时)变得透明

    我正在使用最新的 SDK 版本 API 21 和支持库 21 0 2 进行开发 并且在尝试实施新的材料设计指南时遇到了麻烦 材料设计说我需要有我的primary color and my accent color并将它们应用到我的应用程序上
  • 获取当前 android.intent.category.LAUNCHER 活动的实例

    我创建了一个库项目 并在多个应用程序之间共享 我实现了一个简单的会话过期功能 该功能将在一段时间后将用户踢回到登录屏幕 登录屏幕活动是我的主要活动 因此在清单中它看起来像这样
  • 字符串数组文本格式化

    我有这个字符串 String text Address 1 Street nr 45 Address 2 Street nr 67 Address 3 Street nr 56 n Phone number 000000000 稍后将被使用
  • .isProviderEnabled(LocationManager.NETWORK_PROVIDER) 在 Android 中始终为 true

    我不知道为什么 但我的变量isNetowrkEnabled总是返回 true 我的设备上是否启用互联网并不重要 这是我的GPSTracker class public class GPSTracker extends Service imp
  • 在activity_main.xml中注释

    我是安卓新手 据我所知 XML 中的注释与 HTML 中的注释相同 使用 形式 我想在 Android 项目的 Activity main xml 配置文件中写一些注释 但它给了我错误 值得注意的是 我使用的是 Eclipse 但目前 我直
  • Android:膨胀布局时出现 StackOverFlowError 和 InvokingTargetException

    首先 对不起我的英语 我在膨胀布局时有一个问题 我有一个自定义视图 从 LinearLayout 扩展而来 称为按钮帮助 我在名为的布局上使用该视图加载活动 我的以下代码在所有设备和模拟器上都能完美运行 但具有 QVGA 屏幕 例如 Sam
  • 将 Intent 包装在 LabeledIntent 中以用于显示目的

    要求 我的应用程序中有一个 共享 按钮 我需要通过 Facebook 分享 我需要选择是否安装原生 Facebook 应用程序 我们的决定是 如果未安装该应用程序 则将用户发送到 facebook com 进行分享 当前状态 我可以检测何时
  • 捕获的图像分辨率太大

    我在做什么 我允许用户捕获图像 将其存储到 SD 卡中并上传到服务器 但捕获图像的分辨率为宽度 4608 像素和高度 2592 像素 现在我想要什么 如何在不影响质量的情况下获得小分辨率图像 例如我可以获取或设置捕获的图像分辨率为原始图像分
  • 将两个文本视图并排放置在布局中

    我有两个文本视图 需要在布局中并排放置 并且必须遵守两条规则 Textview2 始终需要完整显示 如果布局中没有足够的空间 则必须裁剪 Textview1 例子 文本视图1 文本视图2 Teeeeeeeeeeeeeeeeeextview1

随机推荐

  • 干扰器 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 下划线对齐 这就是我正在做的