16.鸿蒙HarmonyOS App(JAVA)滑块组件Slider与评级组件Rating
ability_main.xml
<?xml version="1.0" encoding="utf-8"?>
<DirectionalLayout
xmlns:ohos="http://schemas.huawei.com/res/ohos"
ohos:height="match_parent"
ohos:width="match_parent"
ohos:alignment="center"
ohos:orientation="vertical">
<Text
ohos:id="$+id:text_helloworld"
ohos:height="match_content"
ohos:width="match_content"
ohos:background_element="$graphic:background_ability_main"
ohos:layout_alignment="horizontal_center"
ohos:text="$string:mainability_HelloWorld"
ohos:text_size="30vp"
/>
<Slider
ohos:height="match_content"
ohos:width="match_parent"
ohos:min="0"
ohos:max="160"
ohos:step="5"
ohos:progress="20"
/>
<Text
ohos:id="$+id:rate2"
ohos:height="match_content"
ohos:width="match_content"
ohos:background_element="$graphic:background_ability_main"
ohos:layout_alignment="horizontal_center"
ohos:text="评级组件(Rating)"
ohos:text_size="30vp"
/>
<Rating
ohos:id="$+id:rating_sce"
ohos:height="32vp"
ohos:width="150vp"
ohos:score="3.5"
/>
</DirectionalLayout>
MainAbilitySlice.java文章来源:https://www.toymoban.com/news/detail-806267.html
rating.setGrainSize(1f); //最小的控制粒度 rating.setScore(6f); //当前的评级分数 rating.setIsOperable(false);//设置是否可以交互,true:不可以操作
package com.example.myapplication.slice;
import com.example.myapplication.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Rating;
import ohos.agp.components.element.PixelMapElement;
import ohos.global.resource.Resource;
public class MainAbilitySlice extends AbilitySlice {
@Override
public void onStart(Intent intent) {
super.onStart(intent);
super.setUIContent(ResourceTable.Layout_ability_main);
Rating rating = (Rating) findComponentById(ResourceTable.Id_rating_sce);
rating.setGrainSize(1f); //最小的控制粒度
rating.setScore(6f); //当前的评级分数
rating.setIsOperable(false);//设置是否可以交互,true:不可以操作
Resource resource = null;
try
{
//设置评级分背景:点亮的五角星
rating.setFilledElement(new PixelMapElement(getResourceManager().getResource(ResourceTable.Media_star3)));
//rating.setHalfFilledElement(new PixelMapElement(getResourceManager().getResource(ResourceTable.Media_star3)));
rating.setUnfilledElement(new PixelMapElement(getResourceManager().getResource(ResourceTable.Media_star3a)));
}
catch (Exception e)
{
}
}
@Override
public void onActive() {
super.onActive();
}
@Override
public void onForeground(Intent intent) {
super.onForeground(intent);
}
}
文章来源地址https://www.toymoban.com/news/detail-806267.html
到了这里,关于16.鸿蒙HarmonyOS App(JAVA)滑块组件Slider与评级组件Rating的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!