0

新しい Android アプリケーションを開発しています。アプリケーションで以下のスクリーンショットをデザインする必要があります。私はEclipse IDEを使用しています。

ここに画像の説明を入力

以下のコードを使用して、上記のスクリーンショットを作成しました。しかし、異なるスクリーン プレビュー (4.7 インチ WXGA、4.0 インチ WXGA など) を選択するたびに、下のスクリー ショットで矢印でマークされている内側の画像がずれています。以下は一例であるスクリーンショットです。レイアウト内のすべての画像はアイコン (例: ホーム、共有) です。

<?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="@drawable/bar"
    android:orientation="vertical" >

    <LinearLayout
        android:id="@+id/linearLayout2"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="0.9" >

        <ImageView
            android:id="@+id/imageView2"
            android:layout_width="0dp"
            android:layout_height="50dp"
            android:layout_marginTop="240dp"
            android:layout_weight="1.00"
            android:src="@drawable/rec_button_stop"
            android:visibility="gone" />

    </LinearLayout>

    <LinearLayout  android:id="@+id/linearLayout3"
     android:layout_width="fill_parent"
        android:layout_height="wrap_content"
     android:orientation="horizontal">

    <LinearLayout
        android:id="@+id/linearLayout2"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="0.1" >
        <ImageView android:id="@+id/imageView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="40dip" android:layout_marginTop="90dip"/>

        <ImageView
            android:id="@+id/imageView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="40dip"
            android:layout_marginTop="90dip"
            android:src="@drawable/home" />

    </LinearLayout>

      <LinearLayout
        android:id="@+id/linearLayout2"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="0.1" >


        <ImageView
            android:id="@+id/imageView2"
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:layout_weight="1.00"
            android:src="@drawable/rec_button_stop" />


    </LinearLayout>


    <LinearLayout
        android:id="@+id/linearLayout2"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="0.1" >



        <ImageView
            android:id="@+id/imageView2"
            android:layout_width="30dp"
            android:layout_height="fill_parent"
            android:layout_marginLeft="10dip"
            android:src="@drawable/share" />
    </LinearLayout>

     </LinearLayout>
</LinearLayout>

ここに画像の説明を入力

そのため、異なるサイズの画面プレビューを変更するたびに、より小さな画像 (矢印でマークされたアイコン) を同じ位置 (直線) に固定する必要があります。

いくつかのコードスニペットまたはいくつかのリンクを使用して、誰かが私を案内してくれますか?

4

2 に答える 2

2

@2Vision2 : この問題は、レイアウト コンポーネントで固定余白を使用したために発生します。

さまざまなサイズのデバイスをサポートするには、さまざまなレイアウトを作成する必要があります。単一のレイアウトのみを使用しているため、この問題に直面しています。すべてのサイズのレイアウト用に、アプリの res/ ディレクトリに 4 つのディレクトリを作成します

  • レイアウト (4 インチ未満のデバイス用)
  • layout-800X480 (4 インチ以上および 5 インチ未満のデバイス用)
  • layout-sw620dp (7インチ タブレット用)
  • layout-sw800dp (10 インチ タブレット用)

また、横向きモード用に異なるレイアウトを作成する場合は、横向きモードでもアプリをサポートするために、layout-land、layout-land-800X480、.. ディレクトリを作成します。

于 2013-07-03T19:09:08.613 に答える
1

この xml ファイルを試してみてください。これはすべてのサイズ (土地と港) で普遍的に機能します!実際には、重量の使い方が間違っている可能性があります。これが、WEIGHT を使用してレイアウトと重力を設定する方法を理解するのに役立つことを願っています。

<?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:orientation="vertical" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight=".75" >
    </LinearLayout>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight=".25"
        android:background="@android:color/darker_gray" >

        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:layout_weight=".20"
            android:gravity="center" >

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/ic_launcher" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:layout_weight=".60"
            android:gravity="center|top" >

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/ic_launcher" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:layout_weight=".20"
            android:gravity="center" >

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/ic_launcher" />
        </LinearLayout>
    </LinearLayout>

</LinearLayout>

weight は Relative Layout でも使用できますが、linear Layout で使用する方が好ましい方法です。

まだ質問があれば、お願いします...

于 2013-07-04T09:32:47.610 に答える