Fading edges only work on the top and left

I created a custom ImageViewone that supports basic call scrolling View.scrollBy()in GestureDetector. I wanted to add some feedback on achieving scroll borders, so I turned on attenuation with:

setVerticalFadingEdgeEnabled(true);
setHorizontalFadingEdgeEnabled(true);

but the attenuation works, as I expected, only on the upper and left edges, and the lower and right ones do not disappear. I am sure that these edges do not go beyond the screen, because the view is set to fill_parent in height and width. So what's wrong?


EDIT: Enabling only vertical / horizontal decay edges confirms that only the top / left edges are drawn. Now I'm trying to read View.java (6870 an on) ...

+3
source share
2 answers

It seems that the problem is in, getBottomFadingEdgeStrength()and getRightFadingEdgeStrength(), or better, that I did not redefine them to work with my user view.

These protected methods show the view draw()when to draw fading (and how hard it is to see what it does ScrollViewwhen you approach the scroll limit).

For the top and left edges, this is easy, because in both cases the limit is equal 0, and the default implementation works (in on / off mode), but for the other two I need to redefine the methods to take into account my own scroll frames (in my case, available sizes).

+3
source

, , - xml. , , . , .

<!-- object with fading edges in layout -->
<RelativeLayout>
    <ImageView>
    <LinearLayout background="gradient_left" layout_alignParentStart="true">
    <LinearLayout background="gradient_right" layout_alignParentEnd="true">
</RelativeLayout>


<!-- gradient left xml in drawable-->
<shape>
    <gradient startColor="#000" endColor:"@android:color/transparent" angle="0"
</shape>


<!-- gradient right xml in drawable -->
<shape>
   <gradient startColor="#000" endColor:"@android:color/transparent" angle="180"
</shape>
0

Source: https://habr.com/ru/post/1785931/


All Articles