Android 水平滚动视图上的前景

Android 水平滚动视图上的前景,android,android-layout,horizontalscrollview,Android,Android Layout,Horizontalscrollview,我正在尝试在水平滚动视图上添加前景渐变。一切工作正常,但在滚动梯度与布局移动。以下是本期的截图: 应用程序启动后: 滚动后: xml格式的主布局: <RelativeLayout android:id="@+id/RelativeLayout01" android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/r

我正在尝试在水平滚动视图上添加前景渐变。一切工作正常,但在滚动梯度与布局移动。以下是本期的截图: 应用程序启动后: 滚动后:

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>

如果有人有这样的问题或知道如何解决,请分享:)
提前谢谢。

我想你不能在水平滚动视图中使用前景。前台可绘制是滚动视图从FrameLayout继承的一项功能,似乎滚动视图中未实现此功能支持

不过,重写HorizontalScrollView 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);      
}