Android Studio屏幕旋转但布局不遵循

时间:2015-05-13 12:06:08

标签: android xml android-layout orientation

我需要我的应用程序是面向横向的,但出于某种原因,当我尝试将其更改为水平或横向时,它会给我一个错误,并且程序在运行时崩溃。我是android studio的新手,以及如何正确布局。我在绘图应用程序上遵循了一个教程,但我希望它是横向格式而不是肖像。

奇怪的是,我可以在预览渲染中旋转它。

这就是它现在旋转到风景时的样子: enter image description here

如果有人可以帮助我,我真的很感激!这是活动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="#FFCCCCCC"
tools:context=".Client"
android:orientation="vertical">
<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="50dp"
    android:layout_gravity="center"
    android:orientation="horizontal" >


    <ImageButton
        android:id="@+id/new_btn"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:contentDescription="@string/clear"
        android:src="@drawable/new_pic" />
    <ImageButton
        android:id="@+id/draw_btn"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:contentDescription="@string/brush"
        android:src="@drawable/brush" />
    <ImageButton
        android:id="@+id/erase_btn"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:contentDescription="@string/erase"
        android:src="@drawable/eraser" />
    <ImageButton
        android:id="@+id/save_btn"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:contentDescription="@string/save"
        android:src="@drawable/save" />



</LinearLayout>

<com.exercise.server.DrawingView
    android:id="@+id/drawing"
    android:layout_width="fill_parent"
    android:layout_height="0dp"
    android:layout_marginBottom="3dp"
    android:layout_marginLeft="5dp"
    android:layout_marginRight="5dp"
    android:layout_marginTop="3dp"
    android:layout_weight="0.39"
    android:background="#FFFFFFFF" />

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:orientation="vertical" >
    <!-- Top Row -->
    <LinearLayout

        android:id="@+id/paint_colors"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >
        <ImageButton
            android:layout_width="@dimen/small_brush"
            android:layout_height="@dimen/small_brush"
            android:layout_margin="2dp"
            android:background="#FF660000"
            android:contentDescription="@string/paint"
            android:onClick="paintClicked"
            android:src="@drawable/paint"
            android:tag="#FF660000" />

        <ImageButton
            android:layout_width="@dimen/small_brush"
            android:layout_height="@dimen/small_brush"
            android:layout_margin="2dp"
            android:background="#FFFF0000"
            android:contentDescription="@string/paint"
            android:onClick="paintClicked"
            android:src="@drawable/paint"
            android:tag="#FFFF0000" />

        <ImageButton
            android:layout_width="@dimen/small_brush"
            android:layout_height="@dimen/small_brush"
            android:layout_margin="2dp"
            android:background="#FFFF6600"
            android:contentDescription="@string/paint"
            android:onClick="paintClicked"
            android:src="@drawable/paint"
            android:tag="#FFFF6600" />

        <ImageButton
            android:layout_width="@dimen/small_brush"
            android:layout_height="@dimen/small_brush"
            android:layout_margin="2dp"
            android:background="#FFFFCC00"
            android:contentDescription="@string/paint"
            android:onClick="paintClicked"
            android:src="@drawable/paint"
            android:tag="#FFFFCC00" />

        <ImageButton
            android:layout_width="@dimen/small_brush"
            android:layout_height="@dimen/small_brush"
            android:layout_margin="2dp"
            android:background="#FF009900"
            android:contentDescription="@string/paint"
            android:onClick="paintClicked"
            android:src="@drawable/paint"
            android:tag="#FF009900" />

        <ImageButton
            android:layout_width="@dimen/small_brush"
            android:layout_height="@dimen/small_brush"
            android:layout_margin="2dp"
            android:background="#FF009999"
            android:contentDescription="@string/paint"
            android:onClick="paintClicked"
            android:src="@drawable/paint"
            android:tag="#FF009999" />

    </LinearLayout>
    <!-- Bottom Row -->
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >
        <ImageButton
            android:layout_width="@dimen/small_brush"
            android:layout_height="@dimen/small_brush"
            android:layout_margin="2dp"
            android:background="#FF0000FF"
            android:contentDescription="@string/paint"
            android:onClick="paintClicked"
            android:src="@drawable/paint"
            android:tag="#FF0000FF" />

        <ImageButton
            android:layout_width="@dimen/small_brush"
            android:layout_height="@dimen/small_brush"
            android:layout_margin="2dp"
            android:background="#FF990099"
            android:contentDescription="@string/paint"
            android:onClick="paintClicked"
            android:src="@drawable/paint"
            android:tag="#FF990099" />

        <ImageButton
            android:layout_width="@dimen/small_brush"
            android:layout_height="@dimen/small_brush"
            android:layout_margin="2dp"
            android:background="#FFFF6666"
            android:contentDescription="@string/paint"
            android:onClick="paintClicked"
            android:src="@drawable/paint"
            android:tag="#FFFF6666" />

        <ImageButton
            android:layout_width="@dimen/small_brush"
            android:layout_height="@dimen/small_brush"
            android:layout_margin="2dp"
            android:background="#FFFFFFFF"
            android:contentDescription="@string/paint"
            android:onClick="paintClicked"
            android:src="@drawable/paint"
            android:tag="#FFFFFFFF" />

        <ImageButton
            android:layout_width="@dimen/small_brush"
            android:layout_height="@dimen/small_brush"
            android:layout_margin="2dp"
            android:background="#FF787878"
            android:contentDescription="@string/paint"
            android:onClick="paintClicked"
            android:src="@drawable/paint"
            android:tag="#FF787878" />

        <ImageButton
            android:layout_width="@dimen/small_brush"
            android:layout_height="@dimen/small_brush"
            android:layout_margin="2dp"
            android:background="#FF000000"
            android:contentDescription="@string/paint"
            android:onClick="paintClicked"
            android:src="@drawable/paint"
            android:tag="#FF000000" />
    </LinearLayout>
</LinearLayout>

1 个答案:

答案 0 :(得分:0)

Nvm我修好了。

我的AndroidManifest.xml设置为android:screenOrientation="portrait"

将其更改为横向