?
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文章來源:http://www.zghlxwxcb.cn/news/detail-806267.html
rating.setGrainSize(1f); //最小的控制粒度 rating.setScore(6f); //當前的評級分數(shù) 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); //當前的評級分數(shù)
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);
}
}
?文章來源地址http://www.zghlxwxcb.cn/news/detail-806267.html
到了這里,關于16.鴻蒙HarmonyOS App(JAVA)滑塊組件Slider與評級組件Rating的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網(wǎng)!