Kev*_*vin 9 android android-layout
我想尝试将EditText和Button彼此相邻.我目前的按钮位于右侧,编辑文本左对齐,但按钮显示它位于EditText的顶部.我希望Button从EditText结束的地方开始.
这就是我现在所拥有的:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#004D79">
<RelativeLayout android:id="@+id/relativeLayout1"
android:layout_height="wrap_content"
android:layout_width="wrap_content">
<EditText
android:layout_alignParentLeft="true"
android:text="EditText"
android:layout_marginTop="10dp"
android:id="@+id/editText"
android:layout_height="wrap_content"
android:layout_width="fill_parent">
</EditText>
<Button android:text="Skip"
android:id="@+id/skipButton"
android:textSize="18sp"
android:layout_marginTop="10dp"
android:layout_alignParentRight="true"
android:layout_height="wrap_content"
android:layout_width="80dp">
</Button>
</RelativeLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
我试图通过使EditText宽度具有精确的dp量来设置它,但是当屏幕翻转水平时,EditText和Button之间存在很大的差距.
小智 22
如果你想继续使用相对布局并让编辑文本一直运行到按钮,你可以将它添加到edittext xml
android:layout_toLeftOf="@+id/skipButton"
Run Code Online (Sandbox Code Playgroud)
Chr*_*vey 16
而不是使用RelativeLayout,只需将LinearLayout更改为android:orientation ="horizontal".然后,它内部的所有观点将并排放置.删除alignParent事物(用于相对布局),并设置editText(我相信你想拉伸并填充屏幕)以使layout_weight ="1".
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#004D79"
>
<EditText
android:layout_alignParentLeft="true"
android:text="EditText"
android:layout_weight="1"
android:id="@+id/editText"
android:layout_height="wrap_content"
android:layout_width="fill_parent">
</EditText>
<Button android:text="Skip"
android:id="@+id/skipButton"
android:textSize="18dp"
android:layout_marginTop="10dp"
android:layout_height="wrap_content"
android:layout_width="80dp">
</Button>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
28292 次 |
| 最近记录: |