大家好,我想创建一个带有按钮的菜单页面,如图所示https://i.stack.imgur.com/q1Bx7.jpg我已经尝试过线性布局和表格布局,但它不起作用。谁能帮我?按钮的大小应相对,以便页面在平板电脑和智能手机上正确显示。
编辑:这是我的代码
<TableLayout
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TableRow
android:id="@+id/tableRow1"
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<Button
android:id="@+id/button1"
android:layout_weight="0.50"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
<Button
android:id="@+id/button2"
android:layout_weight="0.50"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
</TableRow>
<TableRow
android:id="@+id/tableRow2"
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<Button
android:id="@+id/button3"
android:layout_weight="0.50"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
<Button
android:id="@+id/button4"
android:layout_weight="0.50"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
</TableRow>
</TableLayout>
这就是我在应用程序中的做法。 你可以参考它。 它执行您在图像中显示的操作。
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal" >
<Button
android:id="@+id/btn1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@null"
android:text="1"
android:textColor="#0099CC"
android:textSize="20sp"
android:textStyle="bold" />
<Button
android:id="@+id/btn2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@null"
android:text="2"
android:textColor="#0099CC"
android:textSize="20sp"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_marginBottom="10sp"
android:layout_marginTop="10dip"
android:layout_weight="1"
android:orientation="horizontal" >
<Button
android:id="@+id/btn3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@null"
android:text="3"
android:textColor="#0099CC"
android:textSize="20sp"
android:textStyle="bold" />
<Button
android:id="@+id/btn4"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@null"
android:text="4"
android:textColor="#0099CC"
android:textSize="20sp"
android:textStyle="bold" />
</LinearLayout>