I want to make the edittext width the same size as button. My EditText is currently very small.开发者_JS百科 I use relative layout.
<TextView
android:id="@+id/aha4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="17dip"
android:text="Vzdevek:"
android:layout_below="@id/aha3" />
<EditText android:id="@+id/nick"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_below="@id/nivo"
android:layout_toRightOf="@id/aha4"/>
<Button android:id="@+id/poslji"
android:text="Pošlji"
android:layout_height="wrap_content"
android:layout_width="20dip"
android:typeface="serif" android:textStyle="bold"
android:layout_alignParentRight="true"
android:layout_below="@id/nivo"
android:layout_toRightOf="@id/nick"/>
What i currently get is this: alt text http://www.shrani.si/f/1Z/x8/2lWB3f8p/device.png
What is the appropriate layout_width for edittext and button?
As you are using something like a row to show the TextView, EditText and button, you can try to use TableLayout: http://developer.android.com/guide/tutorials/views/hello-tablelayout.html
Also, make sure you set android:layout_width="wrap_content"
so that the EditText
use as much space as possible.
Try to assign equal weight to both button and edit text
Yeah, you're right about weight. As a hack you can do this. Not exactly right though.
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="@+id/aha4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="17dip"
android:text="Vzdevek:" />
<Button
android:id="@+id/poslji"
android:text="Pošlji"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:paddingLeft="40dip"
android:paddingRight="40dip"
android:typeface="serif"
android:textStyle="bold"
android:layout_alignParentRight="true" />
<EditText
android:id="@+id/nick"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_toRightOf="@id/aha4"
android:layout_toLeftOf="@id/poslji" />
</RelativeLayout>
I managed to solve it with specifying minWidth and maxWidth for EditText.
精彩评论