0

我有三星 Galaxy S2 和三星 Note 10.1。我首先在 S2 上创建,现在我尝试在 Note10.1 上运行,但它的屏幕尺寸不同。我需要让note10.1的屏幕看起来像S2。

我尝试将大图片放入 xhdpi,但它使用 hdpi 中的图片,适用于每个屏幕尺寸。

Galaxy S2

在此处输入图像描述

注释 10.1

在此处输入图像描述

这是我的xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000000"
android:orientation="vertical" >


<project.kmutt.Action_bar_view
    android:id="@+id/actionBar"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" />

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="20dp"
    android:orientation="vertical" >
</LinearLayout>

<GridView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/gridview"
    android:layout_width="fill_parent"
    android:layout_height="979px"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:layout_weight="0.75"
    android:columnWidth="90px"
    android:numColumns="3" 
    android:gravity="center"
    android:horizontalSpacing="10px"

    android:stretchMode="columnWidth"
    android:verticalSpacing="30px" >
</GridView>

<TableLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|center_horizontal"
    android:shrinkColumns="*"
    android:stretchColumns="*" >

    <TableRow
        android:id="@+id/tableRow1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="#000000" >

        <ImageButton
            android:id="@+id/imageButton1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="#000"
            android:src="@drawable/home" />

        <ImageButton
            android:id="@+id/imageButton2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="#000"
            android:gravity="center_horizontal"
            android:src="@drawable/web" />

        <ImageButton
            android:id="@+id/imageButton3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="#000"
            android:gravity="center_horizontal"
            android:src="@drawable/setting" />

        <ImageButton
            android:id="@+id/imageButton4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="#000"
            android:gravity="center_horizontal"
            android:src="@drawable/about" />
    </TableRow>

    <TableRow
        android:id="@+id/tableRow2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >

        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="center_horizontal"
            android:text="Home" />

        <TextView
            android:id="@+id/textView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="center_horizontal"
            android:text="Website" />

        <TextView
            android:id="@+id/textView3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="center_horizontal"
            android:text="Setting" />

        <TextView
            android:id="@+id/textView4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="center_horizontal"
            android:text="About" />
    </TableRow>
</TableLayout>

</LinearLayout>
4

1 回答 1

1

为两种尺寸之一创建不同的布局文件夹。这些是您可以创建的可能的文件夹结构。

res/layout/my_layout.xml             // layout for normal screen size ("default")
res/layout-small/my_layout.xml       // layout for small screen size
res/layout-large/my_layout.xml       // layout for large screen size
res/layout-xlarge/my_layout.xml      // layout for extra large screen size
res/layout-xlarge-land/my_layout.xml // layout for extra large in landscape orientation

res/drawable-mdpi/my_icon.png        // bitmap for medium density
res/drawable-hdpi/my_icon.png        // bitmap for high density
res/drawable-xhdpi/my_icon.png       // bitmap for extra high density

Android 将my_layout.xml根据运行的设备在正确的文件夹中查找文件。如果找不到特定文件夹(例如layout-xlarge),它将使用my_layout.xml默认res/layout/文件夹中的文件。

您可以在此处找到更多信息

并避免过于频繁地使用 LinearLayouts。如果您为多个屏幕创建一个布局文件,RelativeLayouts 会好很多。

于 2013-04-24T15:14:33.367 回答