开发者

Foreground on HorizontalScrollView

I'm trying to add foreground gradient on HorizontallScrollView. Everything works fine but after scroll gradient moves with layout. Here are screenshots of this issue: After appliaction start: http://img819.imageshack.us/img819/6622/horizontalscroll.jpg and after scrolling: http://img709.imageshack.us/img709/388/horizontalscroll2.jpg

Main layout in 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>

And gradient xml:

<shape xmlns:android="http://schemas.andro开发者_StackOverflowid.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>

If someone had such problem or know how to solve it please share :) Thanks in advance.


I think you can't use foreground in HorizontalScrollView. Foreground drawable is a feature scroll view inherits from FrameLayout and it seems like this feature support is not implemented in scroll view.

It is quite easy however to override HorizontalScrollView draw() method to draw you drawable on top of content. I can even provide you with some code snippets from my project that do the thing.

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);      
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜