2

LinearLayout の上部に 1 つの画像を、LinearLayout の下部に 1 つの画像を配置しようとしています。

しかし、私が試したすべてのことの後、別の画像レイアウトの下に 1 つの画像レイアウトしか取得できません。上に1つ、下に1つ揃えたい。

<LinearLayout 
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:orientation="vertical">
    <ImageView 
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:background="@drawable/bg1"
        android:layout_gravity="top" />
    <ImageView 
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:background="@drawable/bg2"
        android:layout_gravity="bottom" />
</LinearLayout>

RelativeLayout (メイン コンテナー) と layout_alignParentBottom (2 番目のイメージ) を使用してみましたが、それでも問題は解決しません。

ご意見ありがとうございます。

4

2 に答える 2

3

次のRelativeLayoutは正常に動作します(テスト済み)。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/RelativeLayout1"
android:layout_width="wrap_content"
android:layout_height="match_parent" >

<ImageView
    android:id="@+id/ImageView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:background="@drawable/bg1" />

<ImageView
    android:id="@+id/ImageView2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_toRightOf="@+id/ImageView1"
    android:background="@drawable/bg2" />

それでも問題が解決しない場合は、このRelativeLayoutの上のコンテナを確認してください。それがルートである場合、すべてが正常に見えます。

于 2012-04-04T20:45:13.023 に答える
0

これはあなたの問題の解決策です:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <ImageView
        android:id="@+id/imgTop"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:background="@drawable/bg1"
        android:layout_alignParentTop="true" />

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:layout_below="@id/imgTop"
        android:layout_above="@+id/imgBottom">

    </LinearLayout>


    <ImageView
        android:id="@id/imgBottom"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:background="@drawable/bg2"
        android:layout_alignParentBottom="true" />

</RelativeLayout>
于 2012-04-04T20:48:07.033 に答える