use*_*147 13 android android-layout android-button
如何在我的Android应用程序的登录布局中将两个按钮放在同一行?
Sre*_*v R 32
只是做一个线性layout.Set的取向水平和增加两个buttons.Its准备好你会得到你want.Before张贴这样的问题尝试谷歌搜索,你会得到sure.This一段代码会帮助你的答案是什么.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
如果你想在布局中放入两个按钮,那么按钮的重量为1.
最好的解决方案是在LinearLayout中放置2个按钮(具有相等的宽度).
还有一件事,如果你想要相同的"宽度"按钮,那么按下0dp宽度和相同重量的按钮到所有按钮.
如果你想要相同的"高"按钮,那么按下0dp高度和相同重量的按钮到所有按钮.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
android:id="@+id/button1"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="Button" />
<Button
android:id="@+id/button2"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="Button" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
小智 5
用这个把两个按钮放在同一条线上....
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<Button
android:id="@+id/login"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Login"
android:layout_alignParentBottom="true"
/>
<Button
android:id="@+id/cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cancel"
android:layout_toRightOf="@+id/login"
android:layout_alignParentBottom="true"
/>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
46695 次 |
| 最近记录: |