设置的TextView + EDITTEXT +按钮 [英] Set Textview + Edittext + Button
问题描述
欲同一行中把一个TextView,和EDITTEXT和一个按钮,但我有问题,该按钮没有正确对齐到左和在小屏幕的EditText填满整个用
小屏幕:
大屏幕:
我的编纂如下:
<的LinearLayout
机器人:ID =@ + ID /布局1
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
机器人:方向=横向>
<的TextView
机器人:ID =@ + ID / address_textview
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:重力=中心
机器人:文本=@字符串/ address_textview
机器人:TEXTSTYLE =黑体/>
<的EditText
机器人:ID =@ + ID / address_edittext
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:提示=@字符串/ address_textview_hint
机器人:imeActionLabel =@字符串/ search_button
机器人:imeOptions =actionDone
机器人:inputType =textCapWords
机器人:nextFocusDown =@ ID / address_edittext
机器人:nextFocusUp =@ ID / address_edittext
机器人:单线=真/>
< RelativeLayout的
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:方向=横向
机器人:重力=权与GT;
<按钮
机器人:ID =@ + ID / go_button
机器人:layout_width =50dp
机器人:layout_height =35dp
机器人:文本=开始/>
< / RelativeLayout的>
< / LinearLayout中>
首先,很多人会告诉你,提示
是不需要标签Android的解决方案。如果你使用标签或没有,但它确实为你节省空间,尤其是在较小的屏幕我不在乎。这只是一个供参考。
现在,你的 RelativeLayout的
只能有一个按钮
似乎没用......我会删除。您可以使用 layout_weight
让每个查看
占用的空间适量。请务必使 layout_width =0dp
。因此,它可能看起来像
<的LinearLayout
机器人:ID =@ + ID /布局1
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
机器人:方向=横向>
<的TextView
机器人:ID =@ + ID / address_textview
机器人:layout_width =0dp
机器人:layout_height =WRAP_CONTENT
机器人:layout_weight =2
机器人:重力=中心
机器人:文本=@字符串/ address_textview
机器人:TEXTSTYLE =黑体/>
<的EditText
机器人:ID =@ + ID / address_edittext
机器人:layout_width =0dp
机器人:layout_height =WRAP_CONTENT
机器人:layout_weight =3
机器人:提示=@字符串/ address_textview_hint
机器人:imeActionLabel =@字符串/ search_button
机器人:imeOptions =actionDone
机器人:inputType =textCapWords
机器人:nextFocusDown =@ ID / address_edittext
机器人:nextFocusUp =@ ID / address_edittext
机器人:单线=真/>
<按钮
机器人:ID =@ + ID / go_button
机器人:layout_width =0dp
机器人:layout_height =35dp
机器人:layout_weight =1
机器人:文本=开始/>
< / LinearLayout中>
下面我用2,3,1为权重
你的的TextView
,的EditText
和按钮
分别。您可能需要改变那些让你想要什么,但应该给你一个开始。
I want to put in the same row a TextView, and Edittext and a button but I am having the problem that the button is not aligned properly to left and in small screens edittext fills entire with.
Small screen:
Big Screen:
My codification is as follows:
<LinearLayout
android:id="@+id/layout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="@+id/address_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/address_textview"
android:textStyle="bold" />
<EditText
android:id="@+id/address_edittext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="@string/address_textview_hint"
android:imeActionLabel="@string/search_button"
android:imeOptions="actionDone"
android:inputType="textCapWords"
android:nextFocusDown="@id/address_edittext"
android:nextFocusUp="@id/address_edittext"
android:singleLine="true" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="right" >
<Button
android:id="@+id/go_button"
android:layout_width="50dp"
android:layout_height="35dp"
android:text="Go" />
</RelativeLayout>
</LinearLayout>
First, many people will tell you that hint
is Android's solution for not needing the label. I don't care if you use the label or not but it does save you space, especially on smaller screens. That was just an FYI.
Now, your RelativeLayout
that only has a Button
appears to be useless...I would remove that. You can use layout_weight
so that each View
takes up the appropriate amount of space. Make sure to make the layout_width="0dp"
. So it may look something like
<LinearLayout
android:id="@+id/layout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="@+id/address_textview"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:gravity="center"
android:text="@string/address_textview"
android:textStyle="bold" />
<EditText
android:id="@+id/address_edittext"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3"
android:hint="@string/address_textview_hint"
android:imeActionLabel="@string/search_button"
android:imeOptions="actionDone"
android:inputType="textCapWords"
android:nextFocusDown="@id/address_edittext"
android:nextFocusUp="@id/address_edittext"
android:singleLine="true" />
<Button
android:id="@+id/go_button"
android:layout_width="0dp"
android:layout_height="35dp"
android:layout_weight="1"
android:text="Go" />
</LinearLayout>
Here I used 2,3,1 for the weights
of your TextView
, EditText
, and Button
respectively. You may need to change those to get exactly what you want but that should give you a start.
这篇关于设置的TextView + EDITTEXT +按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!