cai*_*emr 9 android android-layout android-spinner android-textinputlayout
我对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>
Run Code Online (Sandbox Code Playgroud)
但是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>
Run Code Online (Sandbox Code Playgroud)
但我担心这在其他设备上不能正常工作,尺寸不同.这是唯一的解决方案吗?
根据你提到的,你想达到这个结果:
使用此代码:
<?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>
Run Code Online (Sandbox Code Playgroud)
希望能帮助到你!!!
| 归档时间: |
|
| 查看次数: |
2697 次 |
| 最近记录: |