如何根据不同的屏幕分辨率和旋转调整图形?

时间:2015-04-17 09:15:33

标签: android

我制作了一个跳棋游戏,xml文件的代码是:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/gamebackground" >

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center_vertical|center_horizontal"
    android:orientation="vertical" >

    <RelativeLayout
        android:id="@+id/relativeLayout1"
        android:layout_width="260dp"
        android:layout_height="260dp"
        android:layout_marginBottom="30dp"
        android:background="@drawable/board_1_" >

        <TableLayout
            android:id="@+id/grid"
            android:layout_width="221dp"
            android:layout_height="213dp"
            android:layout_marginLeft="15dp"
            android:layout_marginStart="15dp"
            android:layout_marginTop="16dp"
            android:stretchColumns="*" >
        </TableLayout>
    </RelativeLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center_horizontal"
        android:orientation="horizontal" >

        <TextView
            android:id="@+id/opponent"
            android:layout_width="150dp"
            android:layout_height="17dp"
            android:layout_marginRight="5dp"
            android:layout_marginEnd="5dp"
            android:gravity="center_vertical|center_horizontal"
            android:textColor="#FFFFFF" />

        <TextView
            android:id="@+id/player"
            android:layout_width="150dp"
            android:layout_height="17dp"
            android:layout_marginLeft="5dp"
            android:layout_marginStart="5dp"
            android:gravity="center_vertical|center_horizontal"
            android:textColor="#FFFFFF" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center_horizontal" >

        <TextView
            android:id="@+id/textView1"
            android:layout_width="110dp"
            android:layout_height="30dp"
            android:layout_marginRight="25dp"
            android:layout_marginEnd="25dp"
            android:layout_marginTop="15dp"
            android:gravity="center_vertical|center_horizontal"
            android:text="0"
            android:textColor="#FFFFFF"
            android:textSize="25sp" />

        <TextView
            android:id="@+id/textView2"
            android:layout_width="110dp"
            android:layout_height="30dp"
            android:layout_marginLeft="25dp"
            android:layout_marginStart ="25dp"
            android:layout_marginTop="15dp"
            android:gravity="center_vertical|center_horizontal"
            android:text="0"
            android:textColor="#FFFFFF"
            android:textSize="25sp" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="100dp"
        android:gravity="center_horizontal" >

        <Button
            android:id="@+id/withdraw"
            style="?android:attr/buttonStyleSmall"
            android:layout_width="140dp"
            android:layout_height="wrap_content"
            android:layout_marginEnd="10dp"
            android:layout_marginRight="10dp"
            android:background="@drawable/mybutton"
            android:minHeight="10dp"
            android:minWidth="70dp"
            android:text="@string/Withdraw"
            android:textSize="20sp" />

        <Button
            android:id="@+id/callfortie"
            style="?android:attr/buttonStyleSmall"
            android:layout_width="140dp"
            android:layout_height="wrap_content"
            android:layout_marginBottom="22dp"
            android:layout_marginLeft="10dp"
            android:layout_marginStart="10dp"
            android:background="@drawable/mybutton"
            android:minHeight="10dp"
            android:minWidth="70dp"
            android:text="@string/Callfortie"
            android:textSize="20sp" />

    </LinearLayout>

</LinearLayout>

我正在以编程方式添加8行,每行包含8个按钮,并设置这些按钮以保存检查器图像...问题是我在Nexus一个模拟器上测试了这个并且看起来像这样

http://i59.tinypic.com/zwb6dj.jpg

但是在不同的分辨率上它看起来像这个

http://i61.tinypic.com/iwucls.jpg

那么有什么帮助吗? :)

1 个答案:

答案 0 :(得分:2)

看起来您没有为多屏幕支持创建xml文件。 您应该按照android开发人员的文档关注多屏幕支持。请点击以下链接获取更多信息。

http://developer.android.com/guide/practices/screens_support.html