设置 EditText 行本身的长度
set EditText line itself length
我想要这样的东西:
___ 是 EditText,() 是按钮,--- 是屏幕的其余部分
___________()
我怎样才能让这条线在按钮出现之前一直占据一席之地?
当我旋转屏幕时,edittext 行也应该到达按钮。
但这就是我得到的:
_______()-----
这是我现在拥有的,不知道要更改什么:
<LinearLayout
android:layout_weight="1"
android:layout_width="wrap_content"
android:weightSum="2"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<EditText
android:maxLength="15"
android:layout_weight="1"
android:layout_width=""
android:layout_height="wrap_content"
android:id="@+id/word" />
<Button
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Submit"
android:id="@+id/submit"
android:layout_gravity="right" />
</LinearLayout>
试试 RelativeLayout
:
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<EditText
android:maxLength="15"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/word"
android:layout_toLeftOf="@+id/submit"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Submit"
android:id="@+id/submit"
android:layout_alignParentRight="true"
android:layout_centerVertical="true" />
</RelativeLayout>
你的按钮应该有 weight=0,所以 EditText 总是得到所有未使用的屏幕 space。瞧瞧。
<LinearLayout
android:layout_weight="1"
android:layout_width="wrap_content"
android:weightSum="2"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<EditText
android:maxLength="15"
android:layout_weight="1"
android:layout_width=""
android:layout_height="wrap_content"
android:id="@+id/word" />
<Button
android:layout_weight="0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Submit"
android:id="@+id/submit"
android:layout_gravity="right" />
</LinearLayout>
我想要这样的东西:
___ 是 EditText,() 是按钮,--- 是屏幕的其余部分
___________()
我怎样才能让这条线在按钮出现之前一直占据一席之地?
当我旋转屏幕时,edittext 行也应该到达按钮。
但这就是我得到的:
_______()-----
这是我现在拥有的,不知道要更改什么:
<LinearLayout
android:layout_weight="1"
android:layout_width="wrap_content"
android:weightSum="2"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<EditText
android:maxLength="15"
android:layout_weight="1"
android:layout_width=""
android:layout_height="wrap_content"
android:id="@+id/word" />
<Button
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Submit"
android:id="@+id/submit"
android:layout_gravity="right" />
</LinearLayout>
试试 RelativeLayout
:
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<EditText
android:maxLength="15"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/word"
android:layout_toLeftOf="@+id/submit"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Submit"
android:id="@+id/submit"
android:layout_alignParentRight="true"
android:layout_centerVertical="true" />
</RelativeLayout>
你的按钮应该有 weight=0,所以 EditText 总是得到所有未使用的屏幕 space。瞧瞧。
<LinearLayout
android:layout_weight="1"
android:layout_width="wrap_content"
android:weightSum="2"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<EditText
android:maxLength="15"
android:layout_weight="1"
android:layout_width=""
android:layout_height="wrap_content"
android:id="@+id/word" />
<Button
android:layout_weight="0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Submit"
android:id="@+id/submit"
android:layout_gravity="right" />
</LinearLayout>