使用TextInputLayout和Spinner对齐的问题 [英] Issue with alignment using TextInputLayout and Spinner
问题描述
我在TextInputLayout和Spinner上存在对齐问题,我希望Spinner下划线与TextInputLayout内部的EditText下划线对齐.这就是我正在做的:
I'm having an alignment issue with the TextInputLayout and the Spinner, I want the Spinner underline aligned with the EditText underline inside of TextInputLayout. This is what I'm doing:
<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>
但是微调框是 下面的小.有人可以帮助我吗?预先感谢.
But the Spinner is a little bit below. Anyone can help me? Thanks in advance.
这就是我想要的:
我达到了此对齐方式,将Spinner layout_marginBottom设置为1.5dp:
I reach this alignment setting the Spinner layout_marginBottom to 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>
但是我担心这在尺寸不同的其他设备上将无法正常工作.这是唯一的解决方案吗?
But I'm afraid this will not work properly in others device, with different size. It is the only solution?
推荐答案
根据您提到的内容,您希望获得以下结果:
From what you mention you want to achive this result:
使用此代码:
<?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>
希望有帮助!
这篇关于使用TextInputLayout和Spinner对齐的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!