0

我正在 Android 中开发一个简单的应用程序。每当我将方向更改为横向时,当我在 MOBILE 设备上运行 APP 时,我的一个按钮会丢失,但我的横向视图在 PC 上的 Andriod Simulator 上运行良好。除此之外,APP 在移动设备上运行良好。我使用 TABLE LAYOUT 作为横向。以下是我的代码,请检查问题出在哪里。ECLIPSE 还显示“此 LinearLayout 布局或其 LinearLayout 父级是无用的”为什么会这样。

资源/布局/activity_sudoku.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:padding="30dip"
    android:orientation="horizontal" >
    <LinearLayout
    android:orientation="vertical"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_gravity="center">

    <TextView
        android:id="@+id/textView1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginBottom="25dip"
        android:text="@string/main_title" />

    <Button
        android:id="@+id/button1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/continue_label" />

    <Button
        android:id="@+id/button2"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"

        android:layout_marginTop="21dp"
        android:text="@string/new_game_label" />

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

        android:layout_marginTop="20dp"
        android:text="@string/about_label" />

    <Button
        android:id="@+id/button4"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="29dp"
        android:text="@string/exit_label" />
</LinearLayout>
</LinearLayout>

(景观视图)res/layout-land/activity_sudoku.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:padding="15dip"
    android:orientation="horizontal" >
    <LinearLayout
        android:orientation="vertical"
    android:layout_height="wrap_content"
    android:layout_width="fill_parent"
    android:layout_gravity="center"
    android:paddingLeft="20dip"
    android:paddingRight="20dip">
        <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_height="wrap_content"
            android:layout_width="wrap_content"
            android:layout_gravity="center"
            android:stretchColumns="*">

        <TableRow>
        <Button
        android:id="@+id/button1"
        android:text="@string/continue_label" />
        <Button
        android:id="@+id/button2"
        android:text="@string/new_game_label" />
        </TableRow>


        <TableRow>
        <Button
        android:id="@+id/button3"
        android:text="@string/about_label" />
        <Button
        android:id="@+id/button4"
        android:text="@string/exit_label" />
        </TableRow>

        </TableLayout>
        </LinearLayout>
        </LinearLayout>
4

1 回答 1

0

好吧,你有 2 个嵌套的 LinearLayout。在这种情况下,一个将毫无用处,因为它只包含第二个 LinearLayout。只需删除一个。

减少 LinearLayout 的 paddingLeft 和 paddingRight 看看是否有帮助。

顺便说一句,对于这个简单的视图,您构建的结构确实很复杂。要在低端设备上获得最佳性能,请避免使用过多的嵌套对象。

干杯,

于 2013-08-05T04:13:35.460 回答