在android中滚动时使scrollview的边缘淡化

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11538873/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 07:58:04  来源:igfitidea点击:

making the edge of the scrollview fade when scrolling in android

androidscrollviewfade

提问by roiberg

I have a ScrollViewwith an image in it.

我有一个ScrollView图像。

I want the edges of the ScrollViewto make a fade effect when I scroll the image. I'm not talking about the effect you get when you get to the end of the scroll. I want the fade to always exist.

ScrollView当我滚动图像时,我希望 的边缘产生淡入淡出效果。我不是在谈论你到达卷轴末尾时获得的效果。我希望淡入淡出永远存在。

That's what i did (not doing any effect):

这就是我所做的(没有任何效果):

<ScrollView
    android:id="@+id/scrollView1"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="0.84"
    android:background="@drawable/screen_nespresso"
    android:fadingEdge="horizontal"
    android:fadingEdgeLength="@dimen/padding_large"
    android:fillViewport="false"
    android:scrollbarAlwaysDrawVerticalTrack="true"
    android:visibility="visible" >

Thanks!

谢谢!

回答by Akshat

I am not sure if you this working, but here is what worked for me:

我不确定你是否这样工作,但这是对我有用的:

<ScrollView android:requiresFadingEdge="vertical">

and in your code, you can do the following

在您的代码中,您可以执行以下操作

ScrollView scroll = findById(); scroll.setFadingEdgeLength(150);

回答by batsheva

this is for horizontal:

这是水平的:

<HorizontalScrollView
    android:id="@+id/scroll"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:requiresFadingEdge="horizontal"
    android:fadingEdgeLength="80dp">

回答by Keerthan Chand

Add these lines in your ScrollView xml code.

在 ScrollView xml 代码中添加这些行。

<ScrollView
    android:id="@+id/scrollView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fadeScrollbars="true"
    android:requiresFadingEdge="vertical"
    android:fadingEdgeLength="50dp">