0

我希望我的布局是固定大小的,比如:320dp x 480dp 作为 ldpi 屏幕分辨率的默认值。

因此,当用户拥有 720x1280 的设备时,布局仍然是 320x480,但会居中。

有什么建议么?我想避免为每个分辨率创建多个布局。

4

2 回答 2

1

对于您的父视图容器,您只需将 layout_width 和 layout_height 设置为所需的大小,然后使其 layout_gravity 等于 center。因此,在您的情况下,您将使用以下内容

<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="320dp"
    android:layout_height="480dp"
    android:layout_gravity="center" >

    <!-- The rest of your layout -->

</LinearLayout>

这应该使视图居中并保持所需的大小。需要注意的是,您可以使用任何布局,而不仅仅是 LinearLayout。

希望这可以帮助!祝你好运。

于 2013-10-16T18:46:30.323 回答
1
<?xml version="1.0" encoding="UTF-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <RelativeLayout android:layout_width="320px"
        android:layout_height="480px"
        android:layout_centerInParent="true"
        android:background="@color/white">

    </RelativeLayout>

</RelativeLayout>

希望这是你想要的。

于 2013-10-16T18:41:44.207 回答