我试图让editText坐在我的布局的右边缘,左边有一个按钮,如下所示:
<RelativeLayout android:id="@+id/FindClientLayout" android:layout_width="@dimen/third_width" android:layout_height="@dimen/half_height" android:layout_alignParentLeft="false" android:layout_alignParentRight="true" android:layout_alignParentTop="false" android:layout_below="@id/HeaderLayout" android:layout_margin="@dimen/fragment_separation" android:layout_toRightOf="@id/scrollViewRecommend" android:background="@drawable/login_border" > <TextView android:id="@+id/textViewFindClient" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_alignParentTop="true" android:text="@string/find_client" android:textAppearance="?android:attr/textAppearanceLarge" android:textColor="@color/Black" /> <EditText android:id="@+id/editTextClient" android:layout_width="@dimen/input_text_width" android:layout_height="wrap_content" android:gravity="center_vertical|right" android:inputType="text"/> <Spinner android:id="@+id/spinnerClientList" android:layout_width="@dimen/input_text_width" android:layout_height="wrap_content" android:layout_below="@id/editTextClient"/> <Button android:id="@+id/buttonDoFind" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center_vertical" android:layout_toLeftOf="@id/editTextClient" android:text="@string/find" /> </RelativeLayout>该按钮不可见,结果如下所示:
我假设按钮是不可见的,因为editText是左对齐的,并覆盖它或将它从布局框架中推出。 为什么editText和spinner左对齐而不是右对齐? 另外,为什么editText不是垂直居中?
I am trying to get an editText to sit on the right edge of my layout, with a button to its left, as follows:
<RelativeLayout android:id="@+id/FindClientLayout" android:layout_width="@dimen/third_width" android:layout_height="@dimen/half_height" android:layout_alignParentLeft="false" android:layout_alignParentRight="true" android:layout_alignParentTop="false" android:layout_below="@id/HeaderLayout" android:layout_margin="@dimen/fragment_separation" android:layout_toRightOf="@id/scrollViewRecommend" android:background="@drawable/login_border" > <TextView android:id="@+id/textViewFindClient" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_alignParentTop="true" android:text="@string/find_client" android:textAppearance="?android:attr/textAppearanceLarge" android:textColor="@color/Black" /> <EditText android:id="@+id/editTextClient" android:layout_width="@dimen/input_text_width" android:layout_height="wrap_content" android:gravity="center_vertical|right" android:inputType="text"/> <Spinner android:id="@+id/spinnerClientList" android:layout_width="@dimen/input_text_width" android:layout_height="wrap_content" android:layout_below="@id/editTextClient"/> <Button android:id="@+id/buttonDoFind" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center_vertical" android:layout_toLeftOf="@id/editTextClient" android:text="@string/find" /> </RelativeLayout>The button is invisible, and the result looks like this:
I assume the button is invisible because the editText is left-aligned and overlays it or pushes it out of the layout frame. Why is are the editText and spinner left aligned rather than right-aligned? Also, why is the editText not centered vertically?
最满意答案
像这样编辑你的xml文件并检查结果
<TextView android:id="@+id/textViewFindClient" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_alignParentTop="true" android:text="@string/find_client" android:textAppearance="?android:attr/textAppearanceLarge" android:textColor="@color/Black" /> <EditText android:id="@+id/editTextClient" android:layout_width="@dimen/input_text_width" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:inputType="text"/> <Spinner android:id="@+id/spinnerClientList" android:layout_width="@dimen/input_text_width" android:layout_height="wrap_content" android:layout_below="@id/editTextClient"/> <Button android:id="@+id/buttonDoFind" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center_vertical" android:layout_toLeftOf="@id/editTextClient" android:text="@string/find" />这应该解决您的问题,即您正在使用重力将edittext置于右侧,但重力实际上用于定位视图的内容而不是视图本身。
如果你仍然面临问题留下评论
Edit you xml file like this and check for result
<TextView android:id="@+id/textViewFindClient" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_alignParentTop="true" android:text="@string/find_client" android:textAppearance="?android:attr/textAppearanceLarge" android:textColor="@color/Black" /> <EditText android:id="@+id/editTextClient" android:layout_width="@dimen/input_text_width" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:inputType="text"/> <Spinner android:id="@+id/spinnerClientList" android:layout_width="@dimen/input_text_width" android:layout_height="wrap_content" android:layout_below="@id/editTextClient"/> <Button android:id="@+id/buttonDoFind" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center_vertical" android:layout_toLeftOf="@id/editTextClient" android:text="@string/find" />this should solve your problem which is , you are using gravity to place the edittext on right but gravity is actually use to position the content of view not the view itself.
If you still face problem leave a comment
更多推荐
发布评论