当前位置:   article > 正文

鸿蒙应用开发 | (Slider) 用法,拖动进度条改变图片大小和透明度_鸿蒙可拖动progressbar

鸿蒙可拖动progressbar

导语:大家好,我是你们的朋友 朋哥,十年码农经验,对技术情有独钟。

今天来一个小小的实战,使用进度条的托送功能,实现改变图片的比例和透明度 。

图片

不多说了,今天的内容简单,下面我们开始今天的文章,还是老规矩,通过如下几点来说:

1,功能的使用场景 
2,用到的属性 
3,实战

简介

鸿蒙中进度条目前有3种方式:RoundProgressBar,ProgressBar,Slider,分别是:圆形,线性,和拖动,今天来说说拖动进度条,该类型的进度条有一个拖动bar用来拖动,通过重写Slider.ValueChangedListener 的函数 onProgressUpdated 实现拖动的操作更新 。
 

用到的属性

Image:
 

  1. image_scane.setScale(i/10,i/10);
  2. image_scane.setAlpha(i/10);

实战

1,添加两个拖动条

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <DirectionalLayout
  3. xmlns:ohos="http://schemas.huawei.com/res/ohos"
  4. ohos:height="match_parent"
  5. ohos:width="match_parent"
  6. ohos:padding="10vp"
  7. ohos:alignment="horizontal_center"
  8. ohos:orientation="vertical">
  9. <Image
  10. ohos:id="$+id:image_scane"
  11. ohos:height="match_content"
  12. ohos:width="match_content"
  13. ohos:scale_mode="clip_center"
  14. ohos:image_src="$media:image"
  15. />
  16. <Text
  17. ohos:height="match_content"
  18. ohos:width="match_content"
  19. ohos:top_margin="100vp"
  20. ohos:text_size="18fp"
  21. ohos:text="改变图片大小"/>
  22. <Slider
  23. ohos:id="$+id:slider_opt"
  24. ohos:height="match_content"
  25. ohos:width="match_parent"
  26. ohos:top_margin="10vp"/>
  27. <Text
  28. ohos:height="match_content"
  29. ohos:width="match_content"
  30. ohos:top_margin="10vp"
  31. ohos:text_size="18fp"
  32. ohos:text="改变图片透明度"/>
  33. <Slider
  34. ohos:id="$+id:slider_opt2"
  35. ohos:height="match_content"
  36. ohos:width="match_parent"
  37. ohos:top_margin="10vp"/>
  38. </DirectionalLayout>

2,添加监听接口

实现 接口 :Slider.ValueChangedListener

重写函数:

  1. @Override
  2. public void onProgressUpdated(Slider slider, int i, boolean b) {
  3. image_scane.setScale(i/10,i/10);
  4. image_scane.setAlpha(i/10);
  5. }
  6. @Override
  7. public void onTouchStart(Slider slider) {
  8. }
  9. @Override
  10. public void onTouchEnd(Slider slider) {
  11. }

在 onProgressUpdated 函数中更新操作:​​​​​​​

image_scane.setScale(i/10,i/10);image_scane.setAlpha(i/10);

源码:
https://gitee.com/codegrowth/haomony-develop/tree/master/SliderChangeImageScanAphen

老规矩 代码不能少,下载代码 运行效果看看,记得点个赞。
源码:
https://gitee.com/codegrowth/haomony-develop/tree/master/ProgressBar​​​​​​​

关注公众号【程序员漫话编程】,后台回复 ”鸿蒙“ ,即可获得上千鸿蒙开源组件。

原创不易,有用就关注一下。要是帮到了你 就给个三连吧,多谢支持。
 

觉得不错的小伙伴,记得帮我 点个赞和关注哟,笔芯笔芯~**

作者:码工
 

有问题请留言或者私信,可以 微信搜索:程序员漫话编程,关注公众号获得更多免费学习资料。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小丑西瓜9/article/detail/233163
推荐阅读
相关标签
  

闽ICP备14008679号