4

Android アプリの xml を動作させようとしていますが、いくつか問題があります。線形レイアウトで同じサイズの画像を並べて表示しようとしています。それらの間、左右両側、および上部に余白が必要です。

このような xml ファイルを作成して、どの画面サイズでも普遍的に使用できるようにするにはどうすればよいですか?

更新:これが私のxmlファイルの抜粋です:

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="fill_horizontal"
    android:gravity="center"
    android:orientation="horizontal" >

<ImageView
        android:id="@+id/area"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" 
        android:contentDescription="@string/app_name"
        android:src="@drawable/area_selector"
        android:layout_gravity="left" 
        android:paddingTop="15dp"/>

    <ImageView
        android:id="@+id/volume"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" 
        android:contentDescription="@string/app_name"
        android:src="@drawable/volume_selector"
        android:layout_gravity="left" 
        android:paddingTop="15dp" />

    </LinearLayout>
4

1 に答える 1

9

次のように、両方の画像に同じ重みを付ける必要があります

  <?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="horizontal" >

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="20dp"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="10dp"
        android:layout_marginTop="20dp"
        android:layout_weight="1"
        android:src="@drawable/input_cell" />

    <ImageView
        android:id="@+id/imageView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="20dp"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="20dp"
        android:layout_marginTop="20dp"
        android:layout_weight="1"
        android:src="@drawable/input_cell" />

</LinearLayout>

あなたの場合、これを使用してください

 <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="fill_horizontal"
        android:gravity="center"
        android:orientation="horizontal" >

    <ImageView
            android:id="@+id/area"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" 
            android:contentDescription="@string/app_name"
            android:src="@drawable/area_selector"
            android:layout_weight="1"
            android:layout_gravity="left" 
            android:paddingTop="15dp"/>

        <ImageView
            android:id="@+id/volume"
            android:layout_width="match_parent"
            android:layout_weight="1"
            android:layout_height="wrap_content" 
            android:contentDescription="@string/app_name"
            android:src="@drawable/volume_selector"
            android:layout_gravity="left" 
            android:paddingTop="15dp" />

        </LinearLayout>
于 2012-10-01T10:29:17.697 に答える