Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/191.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 将微调器与“编辑文本”右侧对齐_Android_Android Edittext_Spinner - Fatal编程技术网

Android 将微调器与“编辑文本”右侧对齐

Android 将微调器与“编辑文本”右侧对齐,android,android-edittext,spinner,Android,Android Edittext,Spinner,我希望微调器出现在编辑文本视图的右侧 当我尝试下面的代码时,只有编辑文本出现,微调器完全消失。我试了很多东西,但都没用 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_

我希望微调器出现在编辑文本视图的右侧

当我尝试下面的代码时,只有编辑文本出现,微调器完全消失。我试了很多东西,但都没用

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:descendantFocusability="beforeDescendants"
android:focusableInTouchMode="true"
tools:context=".MyActivity">

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/linearlayout1"
android:orientation="horizontal">

   <android.support.design.widget.TextInputLayout
    android:id="@+id/text_input_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
       <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/editText"
        android:textSize="20dp"
        android:hint="Duration"
        android:layout_gravity="left"
        android:gravity="center"
        android:layout_marginTop="20dp"
        />
    </android.support.design.widget.TextInputLayout>
       <Spinner
       android:id="@+id/spinner"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:layout_marginTop="20dp"
       android:layout_gravity="right"
       />
</LinearLayout>
<Button
    android:id="@+id/startAlarm"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:layout_below="@+id/linearlayout1"
    android:layout_marginBottom="20dp"
    android:text="Start Alarm Service" />
<Button
    android:id="@+id/stopAlarm"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@+id/startAlarm"
    android:layout_marginBottom="20dp"
    android:text="Stop Alarm" />
 </RelativeLayout>


如何解决此问题?

通过将其容器的
宽度
设置为“匹配父项”
并将
文本输入布局
微调器
宽度
设置为0dp50,您将获得所需的布局:

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/linearlayout1"
    android:orientation="horizontal"
    android:gravity="bottom"
    android:layout_marginBottom="20dp">

    <android.support.design.widget.TextInputLayout
        android:id="@+id/text_input_layout"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="50">
        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/editText"
            android:textSize="20dp"
            android:hint="Duration"
            android:layout_gravity="left"
            android:gravity="center"
            />
    </android.support.design.widget.TextInputLayout>
    <Spinner
        android:id="@+id/spinner"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_gravity="right"
        android:layout_weight="50"
        />
</LinearLayout>
<Button
    android:id="@+id/startAlarm"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:layout_below="@+id/linearlayout1"
    android:layout_marginBottom="20dp"
    android:text="Start Alarm Service" />
<Button
    android:id="@+id/stopAlarm"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@+id/startAlarm"
    android:layout_marginBottom="20dp"
    android:text="Stop Alarm" />



我希望能够找出将字段向上推的下划线错误,但似乎TextInputLayout就是这样做的,因为它是这样设计的:-(

谢谢,它向右对齐了。但是当我在应用程序中看到微调器略高于editText时。我的意思是不要在直线上删除您在
TextInputLayout
上设置的边距。检查我的编辑。看:当您要将两个元素彼此对齐时(在本例中,微调器位于editText的右侧)包含在LinearLayout中,将其
layout\u width
属性设置为与父元素匹配。然后,您所要做的就是更改要对齐的两个元素的
layout\u weight
属性:在本例中,我为每个元素指定了50的值,这样每个元素都将占据屏幕宽度的一半。假设100是一个可用空间,它表示容器的
weightSum
属性的值
LinearLayout
(默认等于100)很好的解释。为什么
weightSum=“bottom”
在LinearLayout中?此解决方案很好,但是当使用
微调器旁边的
TextInputLayout
并在
TextInputLayout
下显示带下划线的错误时,
EditText
将启动,对齐将错过…此问题的任何解决方案?请参见我的屏幕截图: