最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android仿京東搜索框漸變效果

 更新時(shí)間:2019年06月15日 14:22:58   作者:AND_Devil  
這篇文章主要為大家詳細(xì)介紹了Android仿京東搜索框漸變效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

在許多APP中,有的搜索框是一直固定的,有的呢,附加了很多的效果,就比如京東

好吧,誰讓京東那么厲害呢,不說了,開始高仿!

原理:就是自定義scrollview實(shí)現(xiàn)對滑動(dòng)高度的監(jiān)聽而已,如此實(shí)現(xiàn)對搜索框的漸變

先貼上我的自定義scrollview

//自定義ScrollView
public class CustomView extends ScrollView {

 public interface ScrollViewListener {
 void onScrollChanged(CustomView customView, int x, int y, int oldx, int oldy);
 }

 private ScrollViewListener scrollViewListener = null;

 public CustomView(Context context) {
 super(context);
 }

 public CustomView(Context context, AttributeSet attrs,
   int defStyle) {
 super(context, attrs, defStyle);
 }

 public CustomView(Context context, AttributeSet attrs) {
 super(context, attrs);
 }

 public void setScrollViewListener(ScrollViewListener scrollViewListener) {
 this.scrollViewListener = scrollViewListener;
 }

 @Override
 protected void onScrollChanged(int x, int y, int oldx, int oldy) {
 super.onScrollChanged(x, y, oldx, oldy);
 if (scrollViewListener != null) {
  scrollViewListener.onScrollChanged(this, x, y, oldx, oldy);
 }
 }
}

好了,接下來就直接在邏輯代碼中調(diào)用就行了!

 @Override
 public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
 super.onViewCreated(view, savedInstanceState);
 //搜索框在布局最上面
 line.bringToFront();
 mScrollview.setScrollViewListener(new CustomView.ScrollViewListener() {
  @Override
  public void onScrollChanged(CustomView customView, int x, int y, int oldx, int oldy) {
  if (y <= 0) {
   line.setBackgroundColor(Color.argb((int) 0, 227, 29, 26));//AGB由相關(guān)工具獲得,或者美工提供
  } else if (y > 0 && y <= imageHeight) {
   //獲取ScrollView向下滑動(dòng)圖片消失的比例
   float scale = (float) y / imageHeight;
   //更加這個(gè)比例,讓標(biāo)題顏色由淺入深
   float alpha = (255 * scale);
   // 只是layout背景透明
   line.setBackgroundColor(Color.argb((int) alpha, 255, 255, 255));
  }
  }
 });

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論

婺源县| 鄂尔多斯市| 漳平市| 颍上县| 息烽县| 十堰市| 枣强县| 衡东县| 永年县| 木兰县| 鹤壁市| 天峻县| 神池县| 友谊县| 赣榆县| 博罗县| 来宾市| 体育| 苗栗市| 神池县| 翁牛特旗| 龙门县| 平原县| 东台市| 土默特右旗| 雷山县| 自贡市| 施甸县| 仪陇县| 诸城市| 黄浦区| 东光县| 育儿| 合水县| 永登县| 句容市| 弥渡县| 大同县| 水城县| 黄冈市| 伊宁县|