當前位置:首頁 » 安卓系統 » androidseekbar

androidseekbar

發布時間: 2022-07-11 00:45:26

Ⅰ android seekbar怎麼調觸控范圍

//mCurrentView 是Seekbar的父親

private void enlargeSeekBar(){

mCurrentView.setOnTouchListener(new OnTouchListener(){

@Override
public boolean onTouch(View v, MotionEvent event) {
Rect seekRect = new Rect();
mSeekBar.getHitRect(seekRect);

if((event.getY() >= (seekRect.top-50)) && (event.getY()<= (seekRect.bottom+50))){

float y = seekRect.top + seekRect.height()/2;
//seekBar only accept relative x
float x = event.getX()-seekRect.left;
if(x <0) {
x=0;
}
else if(x > seekRect.width()) {
x= seekRect.width();
}
MotionEvent me = MotionEvent.obtain(event.getDownTime(), event.getEventTime(),
event.getAction(), x, y, event.getMetaState());
return mSeekBar.onTouchEvent(me);

}
return false;

}

});
}

Ⅱ android seekbar 有沒有從右到左的解決方法

SeekBar是ProgressBar的擴展,在其基礎上增加了一個可拖動的thumb(註:就是那個可拖動的圖標)。用戶可以觸摸thumb並向左或向右拖動,再或者可以使用方向鍵都可以設置當前的進度等級。不建議把可以獲取焦點的widget放在SeekBar的左邊或右邊。
SeekBar的setProgress是對Seekbar進行進度設置的方法,
通過使用seekbar.setProgress(叮笭恥蝗儕豪抽通處坤0),可以設置成 seekbar的最小值

Ⅲ android中怎麼用SeekBar控制視頻播放的進度

android中用SeekBar控制視頻播放的進度其實現方法如下:

1:第一個類是自定義的一個類 也就是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

}

}
?

2: 第二類就是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 = 0;

/**
* 屏幕寬度
*/
private int screenWidth;

/**
* 自定義隨著拖動條一起移動的空間
*/
private TextMoveLayout textMoveLayout;

private ViewGroup.LayoutParams layoutParams;
/**
* 托動條的移動步調
*/
private float moveStep = 0;

@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(245, 245, 245));
text.setTextColor(Color.rgb(0, 161, 229));
text.setTextSize(16);
layoutParams = new ViewGroup.LayoutParams(screenWidth, 50);
textMoveLayout = (TextMoveLayout) findViewById(R.id.textLayout);
textMoveLayout.addView(text, layoutParams);
text.layout(0, 20, screenWidth, 80);
/**
* 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(0);
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), 20, screenWidth, 80);
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[0]);
int st_m = Integer.valueOf(st[1]);
int st_s = Integer.valueOf(st[2]);

int et_h = Integer.valueOf(et[0]);
int et_m = Integer.valueOf(et[1]);
int et_s = Integer.valueOf(et[2]);

int totalSeconds = (et_h - st_h) * 3600 + (et_m - st_m) * 60
+ (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[0]);
int st_m = Integer.valueOf(st[1]);
int st_s = Integer.valueOf(st[2]);

int h = progress / 3600;

int m = (progress % 3600) / 60;

int s = progress % 60;

if ((s + st_s) >= 60) {

int tmpSecond = (s + st_s) % 60;

m = m + 1;

if (tmpSecond >= 10) {
return_s = tmpSecond + "";
} else {
return_s = "0" + (tmpSecond);
}

} else {
if ((s + st_s) >= 10) {
return_s = s + st_s + "";
} else {
return_s = "0" + (s + st_s);
}

}

if ((m + st_m) >= 60) {

int tmpMin = (m + st_m) % 60;

h = h + 1;

if (tmpMin >= 10) {
return_m = tmpMin + "";
} else {
return_m = "0" + (tmpMin);
}

} else {
if ((m + st_m) >= 10) {
return_m = (m + st_m) + "";
} else {
return_m = "0" + (m + st_m);
}

}

if ((st_h + h) < 10) {
return_h = "0" + (st_h + h);
} else {
return_h = st_h + h + "";
}

return return_h + ":" + return_m + ":" + return_s;
}
}

3: 接下來這個就是布局文件了,其中會用到一些色值!

<?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>

4: 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>

5: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>

Ⅳ android開發中如何設置seekbar的最小值

SeekBar是ProgressBar的擴展,在其基礎上增加了一個可拖動的thumb(註:就是那個可拖動的圖標)。用戶可以觸摸thumb並向左或向右拖動,再或者可以使用方向鍵都可以設置當前的進度等級。不建議把可以獲取焦點的widget放在SeekBar的左邊或右邊。
SeekBar的setProgress是對Seekbar進行進度設置的方法,
通過使用seekbar.setProgress(0),可以設置成 seekbar的最小值

Ⅳ seekbar在android中什麼意思

SeekBar是ProgressBar的擴展,在其基礎上增加了一個可拖動的thumb(註:就是那個可拖動的圖標)。用戶可以觸摸thumb並向左或向右拖動,再或者可以使用方向鍵都可以設置當前的進度等級。不建議把可以獲取焦點的widget放在SeekBar的左邊或右邊。

熱點內容
如何用密碼鎖住並隱藏工作表 發布:2024-03-29 07:03:28 瀏覽:326
按鍵精靈滑鼠腳本 發布:2024-03-29 06:47:41 瀏覽:19
pythonhome 發布:2024-03-29 06:47:36 瀏覽:169
dns配置錯誤怎麼修理 發布:2024-03-29 06:36:15 瀏覽:980
電信客戶6位密碼是什麼 發布:2024-03-29 06:35:42 瀏覽:565
b星演算法找門 發布:2024-03-29 06:27:13 瀏覽:774
小數化分數c語言 發布:2024-03-29 06:20:16 瀏覽:561
如何搭建ai伺服器 發布:2024-03-29 06:20:10 瀏覽:493
用低配置手機玩游戲掉幀怎麼辦 發布:2024-03-29 06:20:06 瀏覽:588
安卓系統的微信如何安裝 發布:2024-03-29 05:48:45 瀏覽:993