Android百度音乐滑动进度条SeekBar
2016-07-12 23:32
411 查看
Android百度音乐滑动进度条SeekBar
这种进度条是系统自带的
布局文件:activity_main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context=".MainActivity"> <SeekBar android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/sb_normal" android:layout_gravity="center_horizontal" /> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/txt_cur" /> </LinearLayout>
展示视图控制文件:MainActivity
package com.example.lenovo.myapplication; import android.app.Activity; import android.content.Context; import android.os.Bundle; import android.widget.SeekBar; import android.widget.TextView; import android.widget.Toast; public class MainActivity extends Activity{ private SeekBar sb_normal; private TextView txt_cur; private Context mContext; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mContext = MainActivity.this; bindViews(); } private void bindViews() { sb_normal = (SeekBar) findViewById(R.id.sb_normal); txt_cur = (TextView) findViewById(R.id.txt_cur); sb_normal.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { txt_cur.setText("当前进度值:" + progress + " / 100 "); } @Override public void onStartTrackingTouch(SeekBar seekBar) { Toast.makeText(mContext, "触碰SeekBar", Toast.LENGTH_SHORT).show(); } @Override public void onStopTrackingTouch(SeekBar seekBar) { Toast.makeText(mContext, "放开SeekBar", Toast.LENGTH_SHORT).show(); } }); } }
再来看一个
SeekBar定制的内容包括滑块,以及轨道
两个素材的名字
norm.png
press.png
布局文件:activity_main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context=".MainActivity"> <SeekBar android:id="@+id/sb_normal" android:layout_width="match_parent" android:layout_height="wrap_content" android:maxHeight="5.0dp" android:minHeight="5.0dp" android:progressDrawable="@drawable/sb_bar" android:thumb="@drawable/sb_thumb"/> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/txt_cur" /> </LinearLayout>
展示视图控制文件:MainActivity
package com.example.lenovo.myapplication; import android.app.Activity; import android.content.Context; import android.os.Bundle; import android.widget.SeekBar; import android.widget.TextView; import android.widget.Toast; public class MainActivity extends Activity{ private SeekBar sb_normal; private TextView txt_cur; private Context mContext; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mContext = MainActivity.this; bindViews(); } private void bindViews() { sb_normal = (SeekBar) findViewById(R.id.sb_normal); txt_cur = (TextView) findViewById(R.id.txt_cur); sb_normal.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { txt_cur.setText("当前进度值:" + progress + " / 100 "); } @Override public void onStartTrackingTouch(SeekBar seekBar) { Toast.makeText(mContext, "触碰SeekBar", Toast.LENGTH_SHORT).show(); } @Override public void onStopTrackingTouch(SeekBar seekBar) { Toast.makeText(mContext, "放开SeekBar", Toast.LENGTH_SHORT).show(); } }); } }
滑块状态Drawable:sb_thumb.xml
norm.png 和 press.png
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="true" android:drawable="@drawable/press"/> <item android:state_pressed="false" android:drawable="@drawable/norm"/> </selector>
条形栏Bar的Drawable:sb_bar.xml
<?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item android:id="@android:id/background"> <shape> <solid android:color="#FFFFD042" /> </shape> </item> <item android:id="@android:id/secondaryProgress"> <clip> <shape> <solid android:color="#FFFFFFFF" /> </shape> </clip> </item> <item android:id="@android:id/progress"> <clip> <shape> <solid android:color="#FF96E85D" /> </shape> </clip> </item> </layer-list>
本文参考学习:/article/1531847.html
相关文章推荐
- Android Service完全解析(二)
- Android HotFix动态加载框架介绍
- (4.3.2.12)Android和Java的轻巧Wire协议缓冲器
- 关于在Android Studio中使用Assets目录下的资源的问题
- SwipeRefreshLayout + RecyclerView实现上拉加载和下拉刷新
- android View属性之dispatchTouchEvent,onInterceptTouchEvent,onTouchEvent
- AndroidStudio项目提交(更新)到github最详细步骤
- Xml解析
- Android事件的传递机制
- (15.1.18)为什么Android开发者应该使用FlatBuffers替代JSON?
- Android 2016的一些新东西
- Android中JNI使用详解(2)---Android Studio中NDK环境配置
- Android LayoutInflater原理分析,带你一步步深入了解View(一)
- (15.1.17)鹅厂专家详解Android N适配要点
- Think4Android(二)之Button
- 一个Android JAVA代码中的各显示单位转换工具
- Android Studio官方文档之创建可调整大小的位图
- android服务之录音功能
- 安卓布局中的一点经验
- Android中PopupWindow的使用