mercredi 13 mai 2015

Android Studio Screen rotates but layout doesn't follow

I need my app to be landscape oriented, but for some reason, when I try to change it to horizontal or landscape, it gives me an error and the program crashes when I run it. I'm pretty new to android studio and how to layout properly. I followed a tutorial, on a drawing app, but I want it to be a landscape format instead of portrait.

The odd thing is that I can rotate it in preview render just fine.

This is what it looks like when it's rotated to landscape now: enter image description here

If someone could help me out I'd be really thankful! Here's the activity xml code:

<LinearLayout xmlns:android="http://ift.tt/nIICcg"

xmlns:tools="http://ift.tt/LrGmb4"
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>

Aucun commentaire:

Enregistrer un commentaire