Android 将四个按钮置于屏幕四分之一的中央
我想这样做:Android 将四个按钮置于屏幕四分之一的中央,android,android-layout,Android,Android Layout,我想这样做: 按钮1居中于屏幕左上角 右上角的按钮2 左下角的按钮3 右下角有三到四个按钮 我是新来的,所以不能发照片。 我尝试了不同的布局,但没有结果 谢谢您的帮助。您需要的是一个相对人: 大致如下: <RelativeLayout> <Button android:layout_alignParentTop="true" android:layout_alignParentLeft="true" /> <Button android:layo
- 按钮1居中于屏幕左上角
- 右上角的按钮2
- 左下角的按钮3
- 右下角有三到四个按钮
谢谢您的帮助。您需要的是一个相对人: 大致如下:
<RelativeLayout>
<Button android:layout_alignParentTop="true" android:layout_alignParentLeft="true" />
<Button android:layout_alignParentTop="true" android:layout_alignParentRight="true" />
<Button android:layout_alignParentBottom="true" android:layout_alignParentLeft="true" />
</RelativeLayout>
从这一点,你应该能够找出其余的。我建议阅读RelativeLayout及其对齐参数
编辑-在注释中解释后,尝试以下操作:
<LinearLayout android:orientation="vertical">
<LinearLayout android:orientation="horizontal" android:layout_weight=".5">
<LinearLayout android:layout_weight=".5">
<Button android:layout_gravity="center" />
</LinearLayout>
<LinearLayout android:layout_weight=".5">
<Button android:layout_gravity="center" />
</LinearLayout>
</LinearLayout>
<LinearLayout android:orientation="horizontal" android:layout_weight=".5">
<LinearLayout android:layout_weight=".5">
<Button android:layout_gravity="center" />
</LinearLayout>
<LinearLayout android:layout_weight=".5">
<Button android:layout_gravity="center" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
这将用4个大小相等的“块”填充屏幕,并在每个块的中心直接放置一个按钮。大约5分钟前,有一个问题发布了
我不想无礼,但你应该更加努力。经过一些工作,我用一个表格布局和一些线性布局完成了它
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/TableLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:weightSum="4" >
<TableRow
android:id="@+id/tableRow1"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="2"
android:gravity="center" >
<LinearLayout
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical" >
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 1" />
</LinearLayout>
<LinearLayout
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical" >
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 2" />
</LinearLayout>
</TableRow>
<TableRow
android:id="@+id/tableRow2"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="2"
android:gravity="center" >
<LinearLayout
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical" >
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 3" />
</LinearLayout>
<LinearLayout
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1.0"
android:gravity="center"
android:orientation="vertical" >
<Button
android:id="@+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 4" />
</LinearLayout>
</TableRow>
您应该标记为重复或创建注释,而不是将其作为答案发布,因为答案不适用于“我该怎么做”问题。您应该阅读网站上提供的文档,尝试一些至少相近的内容,然后在这里发布您的布局(虽然布局问题并不真正属于这里,但它已经成为一种常见的做法,如果不是不合适的话)。欲了解更多信息,请咨询网站。对不起,也许我还没有说清楚。这会把按钮放在角落里,我想的是把屏幕分成四部分,然后在每个部分的中心放一个按钮。像这样的东西用你的评论更新了我的帖子。很抱歉,我一开始不明白。谢谢你的帮助,但现在lint说“嵌套权重对性能有害”。我使用了一个TableLayout,现在一切都很好。是的,这不适用于加权线性布局,Eclipse甚至不会编译它,因为缺少布局宽度和高度。是的,你需要添加宽度/高度;设置填充父对象的宽度,以及包裹内容的高度或某些倾斜值。我没有包括它们,因为我以为你会知道如何添加它们。