0

Horizo​​ntallScrollView に前景グラデーションを追加しようとしています。すべて正常に動作しますが、スクロール後にグラデーションがレイアウトとともに移動します。この問題のスクリーンショットは次のとおりです。 アプリケーションの開始後: http://img819.imageshack.us/img819/6622/horizo ​​ntalscroll.jpg およびスクロール後: http://img709.imageshack.us/img709/388/horizo ​​ntalscroll2.jpg

xml のメイン レイアウト:

<RelativeLayout 
android:id="@+id/RelativeLayout01" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
xmlns:android="http://schemas.android.com/apk/res/android"
android:background="@layout/backgroundgradient"
>

<include layout="@layout/header" />


<HorizontalScrollView android:id="@+id/ScrollView1"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:scrollbars="none"
                    android:foreground="@layout/scrollforegrad"
                    android:background="@layout/scrollbgrgrad"
                    android:layout_below="@id/LayoutHeader"
                    >

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

そしてグラデーションxml:

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/mainForegroundGrad"

>
    <gradient 
        android:startColor="@color/scrollForegroundSide"
        android:centerColor="@color/scrollForegroundCenter"
        android:endColor="@color/scrollForegroundSide"
        android:angle="0"
     />
    <corners android:radius="0dp" />
</shape>

誰かがそのような問題を抱えていたり、解決方法を知っている場合は、共有してください:)よろしくお願いします。

4

1 に答える 1

1

Horizo​​ntalScrollView ではフォアグラウンドを使用できないと思います。Foreground drawable は FrameLayout から継承されたスクロール ビューの機能であり、この機能のサポートはスクロール ビューに実装されていないようです。

ただし、Horizo​​ntalScrollView の draw() メソッドをオーバーライドして、コンテンツの上にドローアブルを描画するのは非常に簡単です。私のプロジェクトから、それを実行するコード スニペットをいくつか提供することもできます。

public void draw(Canvas aCanvas) {
    super.draw(aCanvas);

    getDrawingRect(mDrawingRect);

    Gravity.apply(Gravity.CENTER_VERTICAL|Gravity.LEFT, 
            mForegroundDrawable.getIntrinsicWidth(),
            mForegroundDrawable.getIntrinsicHeight(), 
            mDrawingRect, mForegroundDrawableBounds);

    mForegroundDrawableBounds.offset(ARROWS_MARGIN_SIDES, ARROWS_MARGIN_VERTICAL);

    mForegroundDrawable.setBounds(mForegroundDrawableBounds);
    mForegroundDrawable.draw(aCanvas);      
}
于 2011-02-03T15:07:13.620 に答える