0

Androidの相対レイアウトを作成しました。このレイアウトでは、アクティビティの4つの側面に4つの画像を表示し、トップバーと背景画像を表示しようとしています。

トップバーと背景画像が正しく表示されます。しかし、4つのうちNexusエミュレーターに表示されているのは2つの画像のみで、残りの2つの画像はエミュレーターに表示されません。画像を左、右の行、左、右の別の行に配置しました。

エミュレータの中央には左側の画像のみが表示され、右側の画像は両方とも表示されません。

ディスプレイに同じスペースですべての画像を表示するにはどうすればよいですか。私のレイアウトを以下に示します

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:background="@drawable/background"
        android:gravity="center_horizontal"
        android:orientation="vertical"
        tools:context=".MainActivity" >

        <ImageView
            android:id="@+id/topbannerimg"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="false"
            android:layout_alignParentTop="true"
            android:background="@drawable/topbanner"
            android:contentDescription="@string/topbar"
            android:src="@drawable/mtnlogotext" />

        <ImageView
            android:id="@+id/csrimg"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_below="@+id/topbannerimg"
            android:contentDescription="@string/csrstr"
            android:src="@drawable/customerservice" />

        <ImageView
            android:id="@+id/virtualstoreimg"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/topbannerimg"
            android:contentDescription="@string/virstr"
            android:src="@drawable/virtualstore" />

        <ImageView
            android:id="@+id/mtnstorelocatorimg"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_below="@+id/csrimg"
            android:contentDescription="@string/storestr"
            android:src="@drawable/storelocater" />

        <ImageView
            android:id="@+id/mtnviewimg"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/virtualstoreimg"
            android:layout_toRightOf="@+id/mtnstorelocatorimg"
            android:contentDescription="@string/viewstr"
            android:src="@drawable/mtnview" />

    </RelativeLayout>
4

3 に答える 3

0

5つの画像の1つを一番上に、次に2つの行をそれぞれ2つの画像で保持しようとしていると思います。

コードを少し変更しました。それを試してみてください。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:gravity="center_horizontal"
    android:orientation="vertical"
    tools:context=".MainActivity" >

    <ImageView
        android:id="@+id/topbannerimg"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:background="@drawable/topbanner"
        android:contentDescription="@string/topbar"
        android:src="@drawable/mtnlogotext" />

    <RelativeLayout
        android:id="@+id/row1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/topbannerimg" >

        <ImageView
            android:id="@+id/csrimg"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:contentDescription="@string/csrstr"
            android:src="@drawable/customerservice" />

        <ImageView
            android:id="@+id/virtualstoreimg"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_toRightOf="@id/csrimg"
            android:contentDescription="@string/virstr"
            android:src="@drawable/virtualstore" />
    </RelativeLayout>

    <RelativeLayout
        android:id="@+id/row2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/row1" >

        <ImageView
            android:id="@+id/mtnstorelocatorimg"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_below="@id/csrimg"
            android:contentDescription="@string/storestr"
            android:src="@drawable/storelocater" />

        <ImageView
            android:id="@+id/mtnviewimg"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/virtualstoreimg"
            android:layout_toRightOf="@id/mtnstorelocatorimg"
            android:contentDescription="@string/viewstr"
            android:src="@drawable/mtnview" />
    </RelativeLayout>

</RelativeLayout>
于 2012-12-24T06:01:51.213 に答える
0
I have used android:layout_width="145dp" and  android:layout_height="100dp" in the images, now the layout is appearing correctly, with images placed in correct rows and columns


<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:background="@drawable/background"
    android:gravity="center_horizontal"
    android:orientation="vertical"
    android:padding="10dp"
    tools:context=".MainActivity" >

    <ImageView
        android:id="@+id/topbannerimg"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="false"
        android:layout_alignParentTop="true"
        android:background="@drawable/topbanner"
        android:contentDescription="@string/topbar"
        android:src="@drawable/mtnlogotext" />

    <ImageView
        android:id="@+id/csrimg"
        android:layout_width="145dp"
        android:layout_height="100dp"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/topbannerimg"
        android:contentDescription="@string/csrstr"
        android:src="@drawable/customerservice" />

    <ImageView
        android:id="@+id/virtualstoreimg"
        android:layout_width="145dp"
        android:layout_height="100dp"
        android:layout_below="@+id/topbannerimg"
        android:layout_alignParentLeft="false"
        android:layout_toRightOf="@+id/csrimg"
        android:contentDescription="@string/virstr"
        android:src="@drawable/virtualstore" />

    <ImageView
        android:id="@+id/mtnstorelocatorimg"
        android:layout_width="145dp"
        android:layout_height="100dp"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/csrimg"
        android:contentDescription="@string/storestr"
        android:src="@drawable/storelocater" />

    <ImageView
        android:id="@+id/mtnviewimg"
        android:layout_width="145dp"
        android:layout_height="100dp"
        android:layout_below="@+id/virtualstoreimg"
        android:layout_toRightOf="@+id/mtnstorelocatorimg"
        android:contentDescription="@string/viewstr"
        android:src="@drawable/mtnview" />

</RelativeLayout>
于 2012-12-31T05:02:49.513 に答える
0

コードを変更しました。アイコン画像を実際の画像に置き換えるだけです。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:background="#ff4455"
    tools:context=".MainActivity" >

    <ImageView
        android:id="@+id/topbannerimg"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="false"
        android:layout_alignParentTop="true"
        android:background="#222222"
        android:contentDescription="@string/topbar"
        android:src="@drawable/ic_launcher" />

    <ImageView
        android:id="@+id/csrimg"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/topbannerimg"
        android:contentDescription="@string/csrstr"
        android:src="@drawable/ic_launcher" />

    <ImageView
        android:id="@+id/virtualstoreimg"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_below="@+id/topbannerimg"
        android:contentDescription="@string/virstr"
        android:src="@drawable/ic_launcher" />

    <ImageView
        android:id="@+id/mtnstorelocatorimg"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentBottom="true"
        android:contentDescription="@string/storestr"
        android:src="@drawable/ic_launcher" />

    <ImageView
        android:id="@+id/mtnviewimg"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
         android:layout_alignParentBottom="true"
        android:contentDescription="@string/viewstr"
        android:layout_alignParentRight="true"
        android:src="@drawable/ic_launcher" />

</RelativeLayout>

ここに画像の説明を入力してください

レイアウトのデザインがよくわかりませんので、ご希望のレイアウトの画像をアップロードしてください。

于 2012-12-31T05:36:39.767 に答える