我正在Android中开发一个简单的应用程序。每当我将方向更改为横向时,当我在MOBILE设备上运行APP时,我的一个按钮会丢失,但我的横向视图可以在PC上使用Andriod Simulator。除此之外,APP在移动设备上运行正常。我使用TABLE LAYOUT进行横向定位。以下是我的代码,请查看问题所在。此外,ECLIPSE显示“此LinearLayout布局或其LinearLayout父级是无用的”为什么会这样。
RES /布局/ 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>
(FOR LANDSCAPE VIEW)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>
答案 0 :(得分:0)
好吧,你有2个嵌套的LinearLayout。在这种情况下,一个将是无用的,因为它只包含第二个LinearLayout。只需删除一个。
减少LinearLayout的paddingLeft和paddingRight以查看它是否有帮助。
顺便说一下,你构建的结构对于这个简单的视图来说真的很复杂。要在低端设备上获得最佳性能,请避免使用太多嵌套对象。
干杯,