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

Android仿京東搜索框漸變效果

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

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

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

原理:就是自定義scrollview實(shí)現(xiàn)對滑動高度的監(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向下滑動圖片消失的比例
   float scale = (float) y / imageHeight;
   //更加這個比例,讓標(biāo)題顏色由淺入深
   float alpha = (255 * scale);
   // 只是layout背景透明
   line.setBackgroundColor(Color.argb((int) alpha, 255, 255, 255));
  }
  }
 });

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

相關(guān)文章

最新評論

SHOW| 西丰县| 宜都市| 湛江市| 新闻| 满洲里市| 兖州市| 米易县| 东至县| 灵台县| 漳州市| 兴仁县| 武安市| 义乌市| 商洛市| 武川县| 英山县| 元谋县| 娱乐| 阜康市| 缙云县| 水富县| 淄博市| 贺州市| 上高县| 苏尼特左旗| 阿鲁科尔沁旗| 扎囊县| 寻乌县| 兴城市| 乌恰县| 台北县| 新营市| 合水县| 施甸县| 天台县| 平原县| 驻马店市| 盐边县| 东丽区| 冕宁县|