国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Android > 正文

Android自定義SeekBar滑動顯示數字

2019-12-12 05:11:46
字體:
來源:轉載
供稿:網友

先來上個效果圖:

當滑動時:數值顯示,滑動停止時顯示數字,使用FrameLayout結合SeekBar。

首先我們看看。

Layout:

<?xml version="1.0" encoding="utf-8"?><merge xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools"> <RelativeLayout  android:id="@+id/wrapper_seekbar_indicator"  android:layout_width="wrap_content"  android:layout_height="wrap_content">  <ImageView   android:id="@+id/img_seekbar_indicator"   android:layout_width="wrap_content"   android:layout_height="wrap_content"   android:layout_alignParentTop="true" />  <TextView   android:id="@+id/txt_seekbar_indicated_progress"   android:layout_width="wrap_content"   android:layout_height="wrap_content"   android:gravity="center"   android:textColor="#333333"   android:textSize="@dimen/space_12"   tools:text="100" /> </RelativeLayout> <RelativeLayout  android:id="@+id/wrapper_seekbar"  android:layout_width="wrap_content"  android:layout_height="wrap_content">  <SeekBar   android:id="@+id/seekbar"   style="@style/Widget.SeekBar.Normal"   android:layout_width="match_parent"   android:layout_height="wrap_content" /> </RelativeLayout></merge>

需要自定義可再上面修改圖片問題顏色等,或者自己封裝起來。

初始化函數。

private void init(Context context, AttributeSet attrs, int defStyle) {  View view = LayoutInflater.from(context).inflate(    R.layout.view_seekbar_indicated, this);  bindViews(view);  if (attrs != null)   setAttributes(context, attrs, defStyle);  mSeekBar.setOnSeekBarChangeListener(this);  mTextViewProgress.setText(String.valueOf(mSeekBar.getProgress()));  getViewTreeObserver().addOnGlobalLayoutListener(    new ViewTreeObserver.OnGlobalLayoutListener() {     @TargetApi(Build.VERSION_CODES.JELLY_BEAN)     @Override     public void onGlobalLayout() {      mMeasuredWidth = mSeekBar.getWidth()        - mSeekBar.getPaddingLeft()        - mSeekBar.getPaddingRight();      mSeekBar.setPadding(        mSeekBar.getPaddingLeft(),        mSeekBar.getPaddingTop()          + mWrapperIndicator.getHeight(),        mSeekBar.getPaddingRight(),        mSeekBar.getPaddingBottom());      setIndicator();      getViewTreeObserver()        .removeOnGlobalLayoutListener(this);     }    });  // mWrapperIndicator.setVisibility(View.GONE); }

主要是根據是否有改變,和觸摸進行判斷字和圖片的顯示。

 @Override public void onProgressChanged(SeekBar seekBar, int progress,         boolean fromUser) {  setIndicator();  if (mOnSeekBarChangeListener != null)   mOnSeekBarChangeListener.onProgressChanged(seekBar, progress,     fromUser); } @Override public void onStartTrackingTouch(SeekBar seekBar) {  if (mOnSeekBarChangeListener != null) {   mOnSeekBarChangeListener.onStartTrackingTouch(seekBar);   mWrapperIndicator.setVisibility(View.VISIBLE);  } } @Override public void onStopTrackingTouch(SeekBar seekBar) {  if (mOnSeekBarChangeListener != null) {   mOnSeekBarChangeListener.onStopTrackingTouch(seekBar);   mWrapperIndicator.setVisibility(View.GONE);  } }

廢話也不多說,原理很簡單。

工程地址:
https://github.com/xiaoli1993/SeekBarIndicated/tree/47ffcc890fb9c7000bb20d9b248620564c2c8122

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持武林網。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 厦门市| 景东| 三亚市| 石渠县| 高淳县| 沅陵县| 岗巴县| 靖宇县| 沅江市| 武乡县| 扶风县| 常州市| 巴青县| 东乡县| 二连浩特市| 通辽市| 大田县| 通化市| 太仓市| 大同市| 菏泽市| 图片| 老河口市| 怀来县| 盘锦市| 凤山县| 岱山县| 保康县| 龙泉市| 平舆县| 石柱| 仁寿县| 隆回县| 长阳| 弥渡县| 喀喇沁旗| 鄱阳县| 武威市| 普兰店市| 田阳县| 大宁县|