日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

【鸿蒙 HarmonyOS】UI 组件 ( 拖动条 Slider 组件 )

發(fā)布時間:2025/6/17 编程问答 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【鸿蒙 HarmonyOS】UI 组件 ( 拖动条 Slider 组件 ) 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

文章目錄

  • 一、布局中設(shè)置拖動條 Slider 組件
  • 二、代碼中控制拖動條 Slider 組件





一、布局中設(shè)置拖動條 Slider 組件



注意該 Slider 組件與 進度條 Progressbar 組件的區(qū)別 , Progressbar 不能拖動 , 只有顯示功能 ;


布局中設(shè)置的 Slider 拖動條 :

<?xml version="1.0" encoding="utf-8"?> <DirectionalLayoutxmlns:ohos="http://schemas.huawei.com/res/ohos"ohos:height="match_parent"ohos:width="match_parent"ohos:orientation="vertical"><Sliderohos:id="$+id:button"ohos:height="match_content"ohos:width="match_parent"ohos:layout_alignment="horizontal_center"ohos:top_margin="200"ohos:orientation="horizontal"ohos:min="0"ohos:max="100"ohos:progress="66"ohos:background_element="#000000"ohos:progress_color="#00FF00"ohos:text="更新當(dāng)前進度值"ohos:text_size="100"/><Buttonohos:id="$+id:button"ohos:height="match_content"ohos:width="match_content"ohos:top_margin="200"ohos:layout_alignment="horizontal_center"ohos:text="更新當(dāng)前進度值按鈕"ohos:text_size="50"/><Textohos:id="$+id:text"ohos:height="match_content"ohos:width="match_content"ohos:top_margin="200"ohos:background_element="$graphic:background_ability_main"ohos:layout_alignment="horizontal_center"ohos:text="當(dāng)前進度值 : 66"ohos:text_size="100"/></DirectionalLayout>

Slider 相關(guān)標簽屬性說明 :

設(shè)置拖動條方向 : ohos:orientation=“horizontal” , 水平方向 ;

設(shè)置最小值 : ohos:min=“0” , 0 ;

設(shè)置最大值 : ohos:max=“100” , 100 ;

設(shè)置當(dāng)前值 : ohos:progress=“66” , 66 ;

設(shè)置背景顏色 : ohos:background_element="#000000" , 黑色 ;

設(shè)置進度條顏色 : ohos:progress_color="#00FF00" , 綠色 ;


純布局效果展示 :





二、代碼中控制拖動條 Slider 組件



代碼中控制拖動條 Slider 組件 :

界面中有 Slider , Button , Text 三個組件, 點擊按鈕 , 將 Slider 中的進度值顯示到 Text 組件中 ;

package com.example.slider.slice;import com.example.slider.ResourceTable; import ohos.aafwk.ability.AbilitySlice; import ohos.aafwk.content.Intent; import ohos.agp.components.Button; import ohos.agp.components.Component; import ohos.agp.components.Slider; import ohos.agp.components.Text;public class MainAbilitySlice extends AbilitySlice {@Overridepublic void onStart(Intent intent) {super.onStart(intent);super.setUIContent(ResourceTable.Layout_ability_main);// 獲取布局文件中的拖動條 SliderSlider slider = (Slider) findComponentById(ResourceTable.Id_slider);// 獲取布局文件中的按鈕 ButtonButton button = (Button) findComponentById(ResourceTable.Id_button);// 獲取布局文件中的文本 TextText text = (Text) findComponentById(ResourceTable.Id_text);// 設(shè)置按鈕點擊事件button.setClickedListener(new Component.ClickedListener() {@Overridepublic void onClick(Component component) {// 獲取當(dāng)前屬性值int progress = slider.getProgress();text.setText("當(dāng)前進度值 : " + progress);}});}@Overridepublic void onActive() {super.onActive();}@Overridepublic void onForeground(Intent intent) {super.onForeground(intent);} }

《新程序員》:云原生和全面數(shù)字化實踐50位技術(shù)專家共同創(chuàng)作,文字、視頻、音頻交互閱讀

總結(jié)

以上是生活随笔為你收集整理的【鸿蒙 HarmonyOS】UI 组件 ( 拖动条 Slider 组件 )的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。