最近有做一个android项目,里面有使用到在播放视频时可以跳播,同时动态显示播放时间。类似于下图 的效果,我只是抽取其中的一部分做展示,刚接到这个事时也是在网上一通找,最后没找到!而且还碰到有些朋友和我有一样的需求,不知该如何做!现在我分享下自己做的!做的不好,多多包涵!因为上传不了附件,就直接贴代码了!

:第一个类是自定义的一个类 也就是SeekBar上方会跟随其一块移动的控件,其实非常简单的一个类

package com.example.textmovebyseekbar;

import android.content.Context;
import android.util.AttributeSet;
import android.view.ViewGroup; //import android.widget.AbsoluteLayout; public class TextMoveLayout extends ViewGroup { public TextMoveLayout(Context context) {
super(context);
// TODO Auto-generated constructor stub
} public TextMoveLayout(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
// TODO Auto-generated constructor stub
} public TextMoveLayout(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
} @Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
// TODO Auto-generated method stub } }
: 第二类就是MainActivity了,代码很简单!稍微看下就懂的了~
package com.example.textmovebyseekbar; import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.ViewGroup;
import android.widget.SeekBar;
import android.widget.TextView; public class MainActivity extends Activity { private SeekBar seekbar = null; private String startTimeStr = "19:30:33"; private String endTimeStr = "21:23:21"; private TextView text, startTime, endTime; /**
* 视频组中第一个和最后一个视频之间的总时长
*/
private int totalSeconds = ; /**
* 屏幕宽度
*/
private int screenWidth; /**
* 自定义随着拖动条一起移动的空间
*/
private TextMoveLayout textMoveLayout; private ViewGroup.LayoutParams layoutParams;
/**
* 托动条的移动步调
*/
private float moveStep = ; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.video_fast_search);
screenWidth = getWindowManager().getDefaultDisplay().getWidth();
text = new TextView(this);
text.setBackgroundColor(Color.rgb(, , ));
text.setTextColor(Color.rgb(, , ));
text.setTextSize();
layoutParams = new ViewGroup.LayoutParams(screenWidth, );
textMoveLayout = (TextMoveLayout) findViewById(R.id.textLayout);
textMoveLayout.addView(text, layoutParams);
text.layout(, , screenWidth, );
/**
* findView
*/
seekbar = (SeekBar) findViewById(R.id.seekbar);
startTime = (TextView) findViewById(R.id.start_time);
endTime = (TextView) findViewById(R.id.end_time);
/**
* setListener
*/
seekbar.setOnSeekBarChangeListener(new OnSeekBarChangeListenerImp()); searchVideos(); } public void searchVideos() {
startTime.setText(startTimeStr);
endTime.setText(endTimeStr);
text.setText(startTimeStr);
totalSeconds = totalSeconds(startTimeStr, endTimeStr);
seekbar.setEnabled(true);
seekbar.setMax(totalSeconds);
seekbar.setProgress();
moveStep = (float) (((float) screenWidth / (float) totalSeconds) * 0.8); } private class OnSeekBarChangeListenerImp implements
SeekBar.OnSeekBarChangeListener { // 触发操作,拖动
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
text.layout((int) (progress * moveStep), , screenWidth, );
text.setText(getCheckTimeBySeconds(progress, startTimeStr));
} // 表示进度条刚开始拖动,开始拖动时候触发的操作
public void onStartTrackingTouch(SeekBar seekBar) { } // 停止拖动时候
public void onStopTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
} /**
* 计算连个时间之间的秒数
*/ private static int totalSeconds(String startTime, String endTime) { String[] st = startTime.split(":");
String[] et = endTime.split(":"); int st_h = Integer.valueOf(st[]);
int st_m = Integer.valueOf(st[]);
int st_s = Integer.valueOf(st[]); int et_h = Integer.valueOf(et[]);
int et_m = Integer.valueOf(et[]);
int et_s = Integer.valueOf(et[]); int totalSeconds = (et_h - st_h) * + (et_m - st_m) *
+ (et_s - st_s); return totalSeconds; } /**
* 根据当前选择的秒数还原时间点
*
* @param args
*/ private static String getCheckTimeBySeconds(int progress, String startTime) { String return_h = "", return_m = "", return_s = ""; String[] st = startTime.split(":"); int st_h = Integer.valueOf(st[]);
int st_m = Integer.valueOf(st[]);
int st_s = Integer.valueOf(st[]); int h = progress / ; int m = (progress % ) / ; int s = progress % ; if ((s + st_s) >= ) { int tmpSecond = (s + st_s) % ; m = m + ; if (tmpSecond >= ) {
return_s = tmpSecond + "";
} else {
return_s = "" + (tmpSecond);
} } else {
if ((s + st_s) >= ) {
return_s = s + st_s + "";
} else {
return_s = "" + (s + st_s);
} } if ((m + st_m) >= ) { int tmpMin = (m + st_m) % ; h = h + ; if (tmpMin >= ) {
return_m = tmpMin + "";
} else {
return_m = "" + (tmpMin);
} } else {
if ((m + st_m) >= ) {
return_m = (m + st_m) + "";
} else {
return_m = "" + (m + st_m);
} } if ((st_h + h) < ) {
return_h = "" + (st_h + h);
} else {
return_h = st_h + h + "";
} return return_h + ":" + return_m + ":" + return_s;
}
}
: 接下来这个就是布局文件了,其中会用到一些色值!之后我会贴出来,还有使用的图片和其他的xml文件

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/bg_whitef5"
android:orientation="vertical" > <LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" > <com.example.textmovebyseekbar.TextMoveLayout
android:id="@+id/textLayout"
android:layout_width="fill_parent"
android:layout_height="40dp" /> <SeekBar
android:id="@+id/seekbar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:focusable="true"
android:maxHeight="4dp"
android:minHeight="4dp"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:progressDrawable="@drawable/po_seekbar"
android:thumb="@drawable/seekbar_thumb" />
</LinearLayout> <RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" > <TextView
android:id="@+id/start_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginLeft="14dp"
android:textColor="@color/bg_lin_95" /> <TextView
android:id="@+id/end_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="14dp"
android:textColor="@color/bg_lin_95" />
</RelativeLayout> </LinearLayout>
:    android:progressDrawable="@drawable/po_seekbar"这句会引用一个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="#c6c6c6" />
</shape>
</item>
<item android:id="@*android:id/secondaryProgress">
<clip>
<shape>
<solid android:color="#c6c6c6" />
</shape>
</clip>
</item>
<item android:id="@*android:id/progress">
<clip>
<shape>
<solid android:color="#06a7fa" />
</shape>
</clip>
</item>
</layer-list>
:android:thumb="@drawable/seekbar_thumb"也会引用一个xml文件 这其中又有用到两张图片 

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@drawable/video_fast_search_nomal" android:state_focused="true" android:state_pressed="false"/>
<item android:drawable="@drawable/video_fast_search_press" android:state_focused="true" android:state_pressed="true"/>
<item android:drawable="@drawable/video_fast_search_press" android:state_focused="false" android:state_pressed="true"/>
<item android:drawable="@drawable/video_fast_search_nomal"/> </selector>

色值:bg_whitef5:#F5F5F5

bg_lin_95:#959595

Android使用SeekBar时动态显示进度且随SeekBar一起移动的更多相关文章

  1. android学习日记03--常用控件progressbar/seekbar

    常用控件 5.progressbar 进度条,比较常用的组件,在某些操作的进度中的可视指示器,为用户呈现操作的进度,还它有一个次要的进度条,用来显示中间进度,如在流媒体播放的缓冲区的进度.一个进度条也 ...

  2. Android——音乐播放器完善——进度条显示当前播放进度,加可拖动进度条(未待解决完问题)

    效果: 问题:可拖动进度条随进度条移动时,会致使音乐卡顿(待解决) xml <?xml version="1.0" encoding="utf-8"?&g ...

  3. Android再学习-20141018-布局-进度条

    20141018-Android再学习 对齐至控件的基准线 为了保证印刷字母的整齐而划定的线(四线三格的第三条线). android:layout_alignBaseline 与父控件的四个边缘对齐( ...

  4. JavaWeb项目实现文件上传动态显示进度

    很久没有更新博客了,这段时间实在的忙的不可开交,项目马上就要上线了,要修补的东西太多了.当我在学习JavaWeb文件上传的时候,我就一直有一个疑问,网站上那些博客的图片是怎么上传的,因为当提交了表单之 ...

  5. WebView之加载网页时增加进度提示

    上一节讲了一些webview的基本使用以及在记载网页时如何屏蔽掉第三方浏览器,使我们自己开发的程序成为一个微型浏览器.那么这一节将一下在webView加载网页的过程中如何加上进度提示.效果图如下: 主 ...

  6. 拖拽进度条(SeekBar)

    拖拽进度条(SeekBar) 监听方法:setOnSeekBarChangeListener 监听器:SeekBar.OnSeekBarChangeListener 简单,直接上代码: 1.Activ ...

  7. Android笔记之文本随滑块移动的SeekBar

    效果图 FloatingTextSeekBar.java package com.bu_ish.blog; import android.content.Context; import android ...

  8. Android笔记(二十三) Android中的ProgressBar(进度条)

    圆形进度条和水平进度条 进度条也是UI界面一种非常实用的组件,通常用于向用户显示某个耗时操作完成的百分比,进度条可以动态的显示进度,避免长时间的执行某个耗时操作时,让用户感觉程序失去了相应,从而更好的 ...

  9. 设置Android Studio启动时可选最近打开过的工程

    Android Studio启动时,默认会打开最近关闭的工程. 如果想Android Studio在启动时,打开欢迎界面(Welcome to Android Studio界面),则可以通过设置Set ...

随机推荐

  1. Apache 80 端口被占用无法重启解决办法

    原文出处 Apache 80 端口被占用无法重启解决办法 www.111cn.net 编辑:tiger 来源:转载使用WEB服务器的朋友都知道80端口是一个用来对外让用户访问的一个端口了,像apach ...

  2. mysql的having语句

    mysql> use qq; Database changed mysql> #查询本店价比市场价省的钱,并且要求省钱200元以上的取出来 mysql> select goods_i ...

  3. js获得文件根目录

    function getRootPath(){ //获取当前网址,如: http://localhost:8083/proj/meun.jsp var curWwwPath = window.docu ...

  4. 当使用VS CODE 时,如果窗口中打开的文件无法识别HTML的话,可以使用以下方法添加要识别的文件类型

    找到该文件并修改\Microsoft VS Code\resources\app\extensions\html\package.json{ "name": "html& ...

  5. Objective-C 成员变量的访问修饰即成员变量可见性解析

    总体来说Objective-C的访问成员变量可见性和C++基本一样,只是多了个@package. 以下是详细说明: 例子: @interface CTPerson : NSObject { @priv ...

  6. O-C相关-10-动态类型检查

    10-动态类型检查 1.动态绑定 1)OC 中方法的调用不由编译器决定,而由运行时决定 2)OC 中没有方法调用,只有消息接收. 一般称消息为选择器 2.动态类型检查 对象在运行时获得类型的能力称为内 ...

  7. 类库探源——System.Drawing

    一.System.Drawing 命名空间简述 System.Drawing 命名空间提供访问 GDI+ 的基本功能,更高级的功能在 System.Drawing.Drawing2D,System.D ...

  8. html中可以使用在块级元素<body>中的元素

    1.<p></p>当在html页面中需要显示大段文字的时候,可以使用p元素标记每一个段落的边界,需要注意的是,段落是块级元素,只允许包含文本和行内元素. 以下标注的是p中的标准 ...

  9. [USACO1.2.2]方块转换 Transformations

    P1205 [USACO1.2]方块转换 Transformations 标签 搜索/枚举 USACO 题目描述 一块N x N(1<=N<=10)正方形的黑白瓦片的图案要被转换成新的正方 ...

  10. centOS 6 python MySQLdb 提示 no module

    http://www.cnblogs.com/czh-liyu/archive/2012/11/30/2796028.html(转) 用python连接本地数据库时,提示no module MySQL ...