9

画面の1つにScrollViewがあります。右端に影を付けたい。これを行う最も簡単な方法は、ScrollViewの子をRelativeLayoutにし、RelativeLayoutの子を2つ持つことです。1つは画面のレイアウトを格納するLinearLayoutで、もう1つはシャドウです。

そのようです...

<ScrollView
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:scrollbars="none" >

            <RelativeLayout
                android:layout_width="fill_parent"
                android:layout_height="wrap_content" >

                <LinearLayout
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:orientation="vertical" >
                <!-- stuff -->
                </LinearLayout>

                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="fill_parent"
                    android:src="@drawable/shadow"
                    android:layout_alignParentRight="true"
                    />
            </RelativeLayout>
        </ScrollView>

残念ながら、これは完全には機能しません。ImageViewは、そのサイズを画像ファイルのサイズに強制します。垂直方向に伸びてRelativeLayoutの高さになることはありません。私も「match_parent」を試しましたが無駄になりました。画像は9パッチです。

アイデア?

4

4 に答える 4

22

ドローアブルコンテンツをソースとして適用するImageViewことには、コンテンツ自体をあまり変更せずに、ビューがコンテンツに対応できることを実行するという固有の要件が伴います。通常、これは、から必要な動作ですImageView

本当に必要なのは、描画可能なコンテンツをbackgroundビューのように設定することで得られる動作ですが、実際にはまったく必要ありませんImageView。背景は、ビューのサイズに関係なく、単純に引き伸ばしたり、塗りつぶしたりするように設計されています。また、を使用しているので、およびいくつかの追加パラメーターRelativeLayoutを追加することにより、シャドウイングしているビューの境界に一致するようにビューに指示できます。idlayout_align

        <RelativeLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" >

            <LinearLayout
                android:id="@+id/content_layout"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical" >
            <!-- stuff -->
            </LinearLayout>

            <View
                android:layout_width="11dp"
                android:layout_height="fill_parent"
                android:layout_alignParentRight="true"
                android:layout_alignTop="@id/content_layout"
                android:layout_alignBottom="@id/content_layout"
                android:background="@drawable/shadow"
                />
        </RelativeLayout>
于 2012-07-16T19:35:17.690 に答える
9

これを試して

<ImageView
                android:layout_width="wrap_content"
                android:layout_height="fill_parent"
                android:background="@drawable/ic_launcher"
                android:scaleType="fitXY"
                android:layout_alignParentRight="true"
                />

これが私が得るものです

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

およびコードID

<?xml version="1.0" encoding="utf-8"?>

<ScrollView
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:fillViewport="true"
    android:scrollbars="none" >

    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical" >

            <!-- stuff -->
        </LinearLayout>

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:layout_alignParentRight="true"
            android:background="@drawable/ic_launcher"
            android:scaleType="fitXY" />
    </RelativeLayout>
</ScrollView>

于 2012-07-16T19:14:50.067 に答える
1

ImageViewあなたの問題は、 or 9-patch 自体とは何の関係もありませんが、すべてをScrollView. Aは、あなたが指示したかどうかに関係なく、直接の子にそのコンテンツを自動的にラップScrollViewせます。ちなみに、どちらもまったく同じことを行います。唯一の違いは、フラグの実際の動作をよりよく反映する名前です。FILL_PARENTMATCH_PARENT

幸いなことに、ビューポートを強制的にフラグで埋める方法が提供されています。これにより、動作が通常のビューScrollViewに設定するのと非常によく似たものになります。FILL_PARENT属性を追加するか、コードからandroid:fillViewport使用してください。setFillViewport()

編集:明確にするために、そのフラグをに設定する必要がありますScrollView。また、ScrollView影が必要な場合は、9-patch を背景として送信できませんか? 実際の画像がどのように見えるかに依存すると思います。あなたのコメントについて: はい、RelativeLayout は子の配置とサイズ変更に関して柔軟ですが、子は親のサイズにバインドされます。

私たちの何人かは、あなたが考えていることとは異なる何かに向かって取り組んでいるかもしれないと感じています. 簡単な図で物事を明確にするのに間違いなく役立ちます。

于 2012-07-16T19:31:31.140 に答える
0

画像の右側に影が必要でした. 次に で単一レイアウトをHorizontal Orientation使用します. 相対レイアウトを使用することに決めたのは良いことです. 使用する

android:orientation="vertical"

このレイアウト内に、これらの 2 つの画像を追加します。それでも疑問がある場合は、それらの 2 つの画像またはサンプル画像を提供してください。コードを提供します。

于 2012-07-16T19:11:33.000 に答える