0

Android アプリでマルチスクリーン サポートを実現しようとしているので、いくつかのレイアウト フォルダー「layout-sw480dp」、「layout-sw600dp」、「layout-sw720dp」、および同じ名前の xml ファイルを用意しました。メインとして 720 dp のレイアウトを使用しており、10.1 インチのタブレットではすべてがきれいに見えますが、4.3 インチのスマートフォンでは対応するレイアウトを読み込めません。たくさんの記事とさまざまな質問を読みましたが、まだ解決策がわかりません。誰かがこれを解決するのを手伝ってくれますか?

デフォルトの xml レイアウトの例:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/blackboard"
android:orientation="vertical" >

<TextView
    android:id="@+id/welcomeTextView"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:layout_marginTop="40dp"
    android:text="@string/welcomeLabel"
    android:textColor="@color/white"
    android:textSize="56sp" />

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:layout_marginLeft="55dp"
    android:layout_marginTop="30dp"
    android:weightSum="100" >

    <TextView
        android:id="@+id/nameLabel"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="5"
        android:text="@string/nameLabel"
        android:textColor="@color/white"
        android:textSize="26sp" />

    <EditText
        android:id="@+id/nameEditText"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginLeft="5dp"
        android:layout_weight="20"
        android:background="@color/white"
        android:textColor="@color/blue"
        android:textSize="26sp" />
</LinearLayout>

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:paddingLeft="55dp"
    android:paddingTop="20dp"
    android:weightSum="100" >

    <TextView
        android:id="@+id/eqNumberLabel"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="5"
        android:text="@string/eqNumberLabel"
        android:textColor="@color/white"
        android:textSize="26sp" />

    <EditText
        android:id="@+id/eqNumberEditText"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginLeft="5dp"
        android:layout_weight="10"
        android:background="@color/white"
        android:inputType="number"
        android:textColor="@color/blue"
        android:textSize="26sp" />
</LinearLayout>

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" 
    android:layout_marginTop="20dp">

    <CheckBox
        android:id="@+id/reducedCheckBox"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="55dp"
        android:layout_marginRight="10dp"
        android:button="@drawable/checkbox"
        android:layout_gravity="center" >
    </CheckBox>

    <TextView
        android:id="@+id/reducedLabel"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/reducedLabel"
        android:textColor="@color/white"
        android:textSize="36sp" />
</LinearLayout>

<Button
    android:background="@drawable/begin_button"
    android:layout_marginTop="20dp"
    android:id="@+id/beginButton"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:enabled="false"
    android:text="@string/beginButton"
    android:textColor="@color/black" 
    android:textSize="36sp"/>

4

2 に答える 2

0

私は同じ問題を抱えていました。これで、onCreate、onConfigurationChanged、およびコードでレイアウトのサイズを変更するだけです。これは、あらゆるサイズの画面で機能します。以下のコードは、デバイスに実際のピクセルを提供します。デフォルトのxmlを提供できますか?

DisplayMetrics dm = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(dm);
    final float width = dm.widthPixels;
    final float height = dm.heightPixels;
于 2015-03-21T20:29:22.730 に答える
0

タブレットのリソースは、サイズと解像度に応じて異なるフォルダーに保管してください。 drawable-large : 7 インチ タブレットの場合 drawable-xlarge: 10 インチ タブレットの場合、電話をサポートするには、次のフォルダーを使用します: drawable-mdpi drawable-hdpi drawable-xhdpi drawable- xxhdpi

PS: 画面サイズと解像度に違いがあります。

于 2015-03-23T06:43:28.850 に答える