Android:在横向模式下遇到TableLayout问题

时间:2013-03-22 08:49:52

标签: android landscape tablelayout

我已经编写了以下xml代码来以表格格式排列按钮,但是当它在模拟器或我的手机设备中运行时,它不能与我一起工作,其中按钮一个接一个地显示(垂直)而最后一个按钮不是显示出来。

代码是:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/background"
android:orientation="horizontal"
android:padding="15dip"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:paddingLeft="20dip"
android:paddingRight="20dip"
    android:orientation="vertical" >
<TextView
    android:text="@string/main_title"
    android:layout_height="wrap_content"
    android:layout_width="wrap_content"
    android:layout_gravity="center"
    android:layout_marginBottom="20dip"
    android:textSize="24.5sp"/>
<TableLayout 
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:stretchColumns="*">
<TableRow >
 <Button 
    android:id="@+id/continue_button"
    android:text="@string/continue_label" />
 <Button
    android:id="@+id/game_button"
    android:text="@string/new_game_label" />
</TableRow>
<TableRow>
  <Button
    android:id="@+id/about_button"
    android:text="@string/about_label" />
    <Button 
    android:id="@+id/exit_button"
    android:text="@string/exit_label"       />
  </TableRow>
  </TableLayout> 
</LinearLayout>

</LinearLayout>

1 个答案:

答案 0 :(得分:0)

这个创建表格布局的例子请用这个验证你的

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" 
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <TableLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <TableRow
            android:id="@+id/tableRow5"
            android:layout_width="wrap_content"
            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/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" />

            <Button
                android:id="@+id/button5"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Button" />

        </TableRow>

        <TableRow
            android:id="@+id/tableRow1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" >

            <Button
                android:id="@+id/button3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Button" />

            <Button
                android:id="@+id/button4"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Button" />

            <Button
                android:id="@+id/button6"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Button" />

            <Button
                android:id="@+id/button7"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Button" />

        </TableRow>


    </TableLayout>

</LinearLayout>

尝试这样做以及澄清

相关问题