Joa*_*kim 0 android android-layout
我可以通过属性android:cacheColorHint来控制ListView的淡化边缘.这一切都很好,非常方便.我可以设置颜色和强度(通过在颜色属性中添加alpha)
从逻辑上讲,我希望控制scrollView的渐弱边缘同样简单,但事实并非如此.有一些解决方案,但它们并不理想.
我的问题是,是否有人找到了更好的解决方案.一种解决方案,可让您在不使用background属性的情况下控制ScrollViews渐变边缘的颜色和强度.
您的解决方案#2(使用ScrollView背景属性)有效,因为您可以克服您提到的一个问题(您可能希望背景和淡入淡出颜色不同).[基于Android 1.6 donut-release2的答案]
我认为这是你正在尝试什么,在哪里边褪色0x8800FF00和一般的背景是不同的(在这种情况下,它0x88FFFFFF在0x8800FF00的顶部只是为了显示甲型相关)和儿童背景的不同还是(按钮和黑白文本部分是不透明的):

注意布局文件中的背景设置:
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/ScrollView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="#8800FF00"
>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#88FFFFFF"
>
<Button android:text="Hello no style" android:layout_width="wrap_content" android:layout_height="wrap_content"/>
...
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<LinearLayout
android:background="@android:color/black"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView android:textColor="#80ffffff" android:text="#80ffffff" android:layout_width="wrap_content" android:layout_height="wrap_content"/>
...
</LinearLayout>
<LinearLayout
android:background="@android:color/white"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView android:textColor="#80ffffff" android:text="#80ffffff" android:layout_width="wrap_content" android:layout_height="wrap_content"/>
...
</LinearLayout>
</LinearLayout>
</LinearLayout>
</ScrollView>
Run Code Online (Sandbox Code Playgroud)
View.java应用于边缘的方法是先画了滚动的背景(如果有的话),然后在屏幕外的位图(称之为ContentBitmap),画出了滚动的内容和应用与DST_OUT xfermode一个的LinearGradient的边缘.DST_OUT仅使用源中的alpha,而LinearGradient/DST_OUT使ContentBitmap的边缘逐渐变得更加透明和黑暗.View.draw()然后通过SRC_OVER xfermode将ContentBitmap合并到主画布,这使得先前绘制的背景通过半透明的ContentBitmap像素显示.
笔记
至于adroid:colorCacheHint,它是ListView(但不是ScrollView)用来覆盖的值View.getSolidColor(),这反过来导致View.draw()调用View.ScrollabilityCache.setFadeColor()并创建SRC_OVER LinearGradient而不是DST_OUT.setFadeColor()迫使梯度范围从hintColor|0xFF000000到0x0.还要注意的是SRC_OVER不使ContentBitmap结果像素任何比它已经是比较透明的,所以淡出的这种纯色的变化确实是一个漆的褪色效果在最上层,而不是淡出的像素-with透明度.
View.java中的淡化边缘功能是私有的; 自定义它是在子类中重新实现它.
我为ListView尝试了相同的背景设置(从ListActivity获得),但似乎淡入淡出已经通过背景应用了.另一天的难题.
| 归档时间: |
|
| 查看次数: |
5302 次 |
| 最近记录: |