【发布时间】:2015-09-14 08:13:15
【问题描述】:
我有一个关于使用MaterialSpinner 视图的具体问题。
我希望微调器与包装在 android.support.design.widget.TextInputLayout 视图组中的 EditText 的右侧完美对齐,以支持浮动标签。
我已经尝试过 LinearLayout 和 RelativeLayout(使用对齐布局属性),但都没有正常工作。
我最终得到了类似于 this 的东西。
以下是我目前的布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<android.support.design.widget.TextInputLayout
android:id="@+id/weightWidget"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1">
<EditText
android:id="@+id/weight"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:ems="10"
android:hint="@string/weight"
android:inputType="number" />
</android.support.design.widget.TextInputLayout>
<fr.ganfra.materialspinner.MaterialSpinner
android:id="@+id/spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:entries="@array/weights_unit_array"
app:ms_alignLabels="false"
app:ms_arrowColor="#0000FF"
app:ms_arrowSize="16dp"
app:ms_floatingLabelColor="#00FF00"
app:ms_floatingLabelText="floating label"
app:ms_hint="@string/unit"
app:ms_multiline="false"
app:spinnerMode="dialog" />
</LinearLayout>
</LinearLayout>
在 Android Studio 中布局设计器的预览中,它似乎是对齐的,但是当我在模拟器或真实设备上运行它时,视图没有对齐,如上一个屏幕截图所示。
【问题讨论】:
标签: android android-layout material-design