当前位置:   article > 正文

16.鸿蒙HarmonyOS App(JAVA)滑块组件Slider与评级组件Rating

16.鸿蒙HarmonyOS App(JAVA)滑块组件Slider与评级组件Rating

 

16.鸿蒙HarmonyOS App(JAVA)滑块组件Slider与评级组件Rating 

ability_main.xml

  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:alignment="center"
  7. ohos:orientation="vertical">
  8. <Text
  9. ohos:id="$+id:text_helloworld"
  10. ohos:height="match_content"
  11. ohos:width="match_content"
  12. ohos:background_element="$graphic:background_ability_main"
  13. ohos:layout_alignment="horizontal_center"
  14. ohos:text="$string:mainability_HelloWorld"
  15. ohos:text_size="30vp"
  16. />
  17. <Slider
  18. ohos:height="match_content"
  19. ohos:width="match_parent"
  20. ohos:min="0"
  21. ohos:max="160"
  22. ohos:step="5"
  23. ohos:progress="20"
  24. />
  25. <Text
  26. ohos:id="$+id:rate2"
  27. ohos:height="match_content"
  28. ohos:width="match_content"
  29. ohos:background_element="$graphic:background_ability_main"
  30. ohos:layout_alignment="horizontal_center"
  31. ohos:text="评级组件(Rating)"
  32. ohos:text_size="30vp"
  33. />
  34. <Rating
  35. ohos:id="$+id:rating_sce"
  36. ohos:height="32vp"
  37. ohos:width="150vp"
  38. ohos:score="3.5"
  39. />
  40. </DirectionalLayout>

 

 

MainAbilitySlice.java

rating.setGrainSize(1f); //最小的控制粒度
rating.setScore(6f); //当前的评级分数
rating.setIsOperable(false);//设置是否可以交互,true:不可以操作
  1. package com.example.myapplication.slice;
  2. import com.example.myapplication.ResourceTable;
  3. import ohos.aafwk.ability.AbilitySlice;
  4. import ohos.aafwk.content.Intent;
  5. import ohos.agp.components.Rating;
  6. import ohos.agp.components.element.PixelMapElement;
  7. import ohos.global.resource.Resource;
  8. public class MainAbilitySlice extends AbilitySlice {
  9. @Override
  10. public void onStart(Intent intent) {
  11. super.onStart(intent);
  12. super.setUIContent(ResourceTable.Layout_ability_main);
  13. Rating rating = (Rating) findComponentById(ResourceTable.Id_rating_sce);
  14. rating.setGrainSize(1f); //最小的控制粒度
  15. rating.setScore(6f); //当前的评级分数
  16. rating.setIsOperable(false);//设置是否可以交互,true:不可以操作
  17. Resource resource = null;
  18. try
  19. {
  20. //设置评级分背景:点亮的五角星
  21. rating.setFilledElement(new PixelMapElement(getResourceManager().getResource(ResourceTable.Media_star3)));
  22. //rating.setHalfFilledElement(new PixelMapElement(getResourceManager().getResource(ResourceTable.Media_star3)));
  23. rating.setUnfilledElement(new PixelMapElement(getResourceManager().getResource(ResourceTable.Media_star3a)));
  24. }
  25. catch (Exception e)
  26. {
  27. }
  28. }
  29. @Override
  30. public void onActive() {
  31. super.onActive();
  32. }
  33. @Override
  34. public void onForeground(Intent intent) {
  35. super.onForeground(intent);
  36. }
  37. }

 

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

闽ICP备14008679号