【问题标题】:Foreground on HorizontalScrollViewHorizo​​ntalScrollView 上的前景
【发布时间】:2011-02-03 12:28:08
【问题描述】:

我正在尝试在 Horizo​​ntallScrollView 上添加前景渐变。一切正常,但滚动渐变随着布局移动后。下面是这个问题的截图: 申请开始后:http://img819.imageshack.us/img819/6622/horizontalscroll.jpg 滚动后:http://img709.imageshack.us/img709/388/horizontalscroll2.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>

如果有人遇到此类问题或知道如何解决,请分享:) 提前致谢。

【问题讨论】:

    标签: android android-layout horizontalscrollview


    【解决方案1】:

    我认为你不能在 Horizo​​ntalScrollView 中使用前景。 Foreground drawable 是从 FrameLayout 继承的功能滚动视图,似乎此功能支持未在滚动视图中实现。

    然而,重写 Horizo​​ntalScrollView draw() 方法来在内容之上绘制可绘制对象是很容易的。我什至可以为您提供我项目中的一些代码 sn-ps。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多