Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Android中创建带有按钮的表格,与平板电脑和智能手机兼容_Android_Xml_Button - Fatal编程技术网

在Android中创建带有按钮的表格,与平板电脑和智能手机兼容

在Android中创建带有按钮的表格,与平板电脑和智能手机兼容,android,xml,button,Android,Xml,Button,嗨,伙计们,我想创建一个菜单页面,按钮如图所示 我已经尝试过线性布局和表格布局,但它不起作用。有人能帮我吗?按钮的大小应该是相对的,这样页面就可以在平板电脑和智能手机上正确显示 编辑:这是我的代码 <TableLayout android:layout_weight="1" android:layout_width="wrap_content" android:layout_height="wrap_content" > <TableRow

嗨,伙计们,我想创建一个菜单页面,按钮如图所示 我已经尝试过线性布局和表格布局,但它不起作用。有人能帮我吗?按钮的大小应该是相对的,这样页面就可以在平板电脑和智能手机上正确显示

编辑:这是我的代码

<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>