1

複数の画面サイズをサポートし、すべての画面が縦向きになる Android 2.2.2 アプリケーションを開発しています。風景はサポートしません。

HTC Desire と Samsung Galaxy Tab 7.7 で次のレイアウトをテストしました。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/mainLayout"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/no_conectado"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/labelSelGateName"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center_horizontal"
        android:layout_marginTop="80dp" />

    <TextView
        android:id="@+id/labelSelOpened"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal" />

    <ProgressBar
        android:id="@+id/indicatorActivityView"
        android:layout_width="20dp"
        android:layout_height="20dp"
        android:layout_marginTop="22dp"
        android:layout_gravity="center_horizontal" />

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="110dp"
        android:layout_marginTop="60dp"
        android:orientation="horizontal" >

        <ImageButton
            android:id="@+id/btnMyGates"
            android:layout_width="50dp"
            android:layout_height="110dp"
            android:layout_marginLeft="20dp"
            android:layout_weight=".33"
            android:background="@null"
            android:contentDescription="@string/layout_empty"
            android:onClick="onGateClick" />

        <LinearLayout
            android:layout_width="90dp"
            android:layout_height="110dp"
            android:layout_weight=".33"
            android:orientation="vertical" >

            <ImageButton
                android:id="@+id/btnOpen"
                android:layout_width="90dp"
                android:layout_height="55dp"
                android:layout_gravity="center_horizontal"
                android:layout_marginLeft="10dp"
                android:layout_marginRight="10dp"
                android:background="@null"
                android:contentDescription="@string/layout_empty"
                android:onClick="onOpenDoorClick" />

            <ImageButton
                android:id="@+id/btnClose"
                android:layout_width="90dp"
                android:layout_height="50dp"
                android:layout_gravity="center_horizontal"
                android:layout_marginTop="10dp"
                android:layout_marginLeft="10dp"
                android:layout_marginRight="10dp"
                android:background="@null"
                android:contentDescription="@string/layout_empty"
                android:onClick="onCloseDoorClick" />

        </LinearLayout>

        <ImageButton
            android:id="@+id/btnOptions"
            android:layout_width="50dp"
            android:layout_height="110dp"
            android:layout_marginRight="20dp"
            android:layout_weight=".33"
            android:background="@null"
            android:contentDescription="@string/layout_empty"
            android:onClick="onOptionClick" />

    </LinearLayout>

    <ImageButton
        android:id="@+id/btnFaqs"
        android:layout_width="110dp"
        android:layout_height="60dp"
        android:layout_gravity="center_horizontal"
        android:layout_marginTop="10dp"
        android:background="@null"
        android:contentDescription="@string/layout_empty"
        android:onClick="onFAQClick" />

    <ImageButton
        android:id="@+id/btnInfo"
        android:layout_width="110dp"
        android:layout_height="60dp"
        android:layout_gravity="right"
        android:layout_marginTop="20dp"
        android:background="@null"
        android:contentDescription="@string/layout_empty"
        android:onClick="onInfoClick" />

</LinearLayout>

ldpi、mdpi、hdpi、x-hdpi のイメージがあります。

背景画像は見栄えがしますが、Samsung Galaxy Tab でテストすると、すべてのウィジェット ( TextViewProgressBarImageButtonなど) が正しい位置にありません。

「Nexus One」をモデルとしてEclipse上でこのレイアウトを設計しました。

ここでは、画面サイズと密度ごとに 1 つのレイアウトのみを使用することをお勧めしますが、うまくいきません。dp単位 やなどを使用してfill_parentいますが、Galaxy Tab では異なります。

x-large画面サイズのレイアウトは必要ですか?

4

2 に答える 2

6

確かに、あなたが受け取ったアドバイスは良かったです: レイアウト ファイルを 1 つだけにすることは可能ですが、コメントで既に提案されているように、dpまたはを使用したとしてもdip、特にすべての画面サイズと利用可能な密度。

代わりに、これらの値をディメンション値へのリンクに置き換える必要があります。

たとえば、の代わりに android:layout_marginLeft="10dp"、次のようなものがあります

android:layout_marginLeft="@dimen/textview_margin_left"

textview_margin_leftはdimens.xmlで定義されており、フォルダーごとに異なる値を持っています。
おそらくフォルダー内のvalues : <dimen name="textview_margin_left">10dp</dimen>
フォルダー内の values-large : <dimen name="textview_margin_left">20dp</dimen>
一方、values-xlarge 内:<dimen name="textview_margin_left">30dp</dimen>

ただし、これは単なる例です。すべての寸法と解像度でテストし、レイアウトに最適な値を見つける必要があります。Eclipseモードでは、 Nexus Oneをクリックし、リストから別のモデルを選択Graphical Layoutするだけで、レイアウトがさまざまなデバイスでどのように見えるかを簡単に把握でき、レイアウトが自動的に更新されます。

また、すべてのテキスト サイズを移動できますdimens.xml。これは、超大型デバイスに非常に役立ちます。

RelativeLayoutハードコーディングされた値の代わりに、オブジェクトの相対的な配置を使用して、多くの複雑なものの代わりに1 つだけを使用するLinearLayoutsことも良い考えです。

于 2012-07-24T08:49:16.783 に答える
1

問題は、レイアウトで使用する静的な値(100dp、60dp)に従っています。現在、問題はより高い解像度にあり、このdpは同じではありません。

つまり、x-large画面のレイアウトを作成する必要があります。また、これらの静的な値は使用しません。アプリケーションが多くの異なる画面サイズで適切に動作するよりも!

すてきな一日を

サファリ

于 2012-07-24T07:45:04.830 に答える