导航:首页 > 操作系统 > androidseekbar样式

androidseekbar样式

发布时间:2023-07-05 21:49:21

⑴ 求助,android里面的seekbar怎么垂直显示

把seekbar复写了。。旋转90度就可以了。

import android.content.Context;
import android.graphics.Canvas;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.widget.SeekBar;

public class SlideBar extends SeekBar {

private int oHeight = 100;
private int oWidth = 30;
private int oProgress = -1;
private int oOffset = -1;;
private float xPos = -1;
private float yPos = -1;
private int top = -1;
private int bottom = -1;
private int left = -1;
private int right = -1;

public SlideBar(Context context) {

super(context);
}

public SlideBar(Context context, AttributeSet attrs) {

super(context, attrs);
oOffset = this.getThumbOffset();
oProgress = this.getProgress();
}

public SlideBar(Context context, AttributeSet attrs, int defStyle) {

super(context, attrs, defStyle);
}

protected synchronized void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {

int height = View.MeasureSpec.getSize(heightMeasureSpec);
oHeight = height;
this.setMeasuredDimension(oWidth, oHeight);
}

protected void onSizeChanged(int w, int h, int oldw, int oldh) {

super.onSizeChanged(h, w, oldw, oldh);
}

// 设置layout
protected void onLayout(boolean changed, int l, int t, int r, int b) {

super.onLayout(changed, l, t, r, b);
left = l;
right = r;
top = t;
bottom = b;
}

// 画出滚动条
protected void onDraw(Canvas c) {
// 旋转
c.rotate(90);
//控制左右位置
c.translate(0,-30);
super.onDraw(c);
}

public boolean onTouchEvent(MotionEvent event) {

xPos = event.getX();
yPos = event.getY();
float progress = 1-(yPos-this.getTop())/(this.getBottom()- this.getTop());
oOffset = this.getThumbOffset();
oProgress = this.getProgress();
Log.d("offset" + System.nanoTime(), new Integer(oOffset).toString());
Log.d("progress" + System.nanoTime(), new Integer(oProgress).toString());
float offset;
offset = progress * (this.getBottom() - this.getTop());
this.setThumbOffset((int)offset);
Log.d("offset_postsetprogress" + System.nanoTime(), new Integer(oOffset).toString());
Log.d("progress_postsetprogress" + System.nanoTime(), new Integer(oProgress).toString());
// this.setProgress((int)(100*event.getY()/this.getBottom()));
this.setProgress((int)(100 * progress));
return true;
}
}

⑵ 安卓开发中 滑动条(seekbar)控件显示异常,是不是我的开发环境有问题,能设置吗图如下:

你的seekbar高度设置为wrap_content试一下。
holo的seekbar主题有点不一样。

开什么国际玩笑。只有相对布局才能用??我做这个好几个月了,没有上百次用这个控件也有几十次了。我都没有发现还有这个隐藏功能

⑶ Android SeekBar,动态显示进度且随SeekBar一起移动

花了点时间做,其实这个东西本没有什么,裂肢主要的问题就是在于seekBar不是顶格的,存在一个空隙,这个空隙又不知道值是多少,所以这个很难计算,后来去看了资料,paddingStart = 0dp,PaddingEnd=0dp 可以使进度条填充到整肆启世个界面,但也不大符旁樱合需求,所以设定paddingStart = 15dp,既能不改变原来seekbar的效果,也可以知道这个间隙是多少。

这里就是计算具体的textview位置的地方了

textview的文本是固定宽度的,动态的太难控制了,不是这种简单的操作能够搞定的。
seekbar的宽度就随意了,注意设置下paddingStart 和 paddingEnd。

xml 如下:

好了效果实现了,这种实现方式算是比较简单了。

⑷ android 怎么实现类似SeekBar的单向调节改成双向调节范围

网上有个重写View实现的,SeekBarPressure

以下是一个使用SeekBar来调节系统音量的实例:
XML代码:
<SeekBar
android:id="@+id/sound"
android:layout_width="150px"
android:layout_height="10px"
android:max="100" //设置拖动条最大值
android:progress="10" //设置拖动条当前值
android:progressDrawable="@layout/seekbar_style" //拖动条样式
android:thumb="@layout/thumb" /> //滑块样式

seekbar_style.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>
<corners android:radius="10dip" />
<gradient android:startColor="#ffffffff"
android:centerColor="#ff000000" android:endColor="#ff808A87"
android:centerY="1" android:angle="270" />
</shape>
</item>

<item android:id="@android:id/progress">
<clip>
<shape>
<corners android:radius="10dip" />
<gradient android:startColor="#ffffffff"
android:centerColor="#ffFFFF00" android:endColor="#ffAABD00"
android:centerY="1" android:angle="270" />
</shape>
</clip>
</item>
</layer-list>

thumb.xml:
<?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/thumb_normal"
/>

<!-- 普通无焦点状态 -->
<item
android:state_focused="false"
android:state_pressed="false"
android:drawable="@drawable/thumb_normal"
/>

</selector>

bacon_seekbar.xml:
<layer-list
xmlns:android="http://schemas.android.com/apk/res/android"
>
<item
android:id="@+android:id/background"
android:drawable="@drawable/thumb_normal" />
<item
android:id="@+android:id/SecondaryProgress"
android:drawable="@drawable/thumb_normal" />
<item
android:id="@+android:id/progress"
android:drawable="@drawable/thumb_normal" />
</layer-list>

java代码:
public class PianoActivity extends Activity {
/** Called when the activity is first created. */
private ImageButton imageButton_white1;
private MediaPlayer mediaPlayer01;
public AudioManager audiomanage;
private TextView mVolume ; //显示当前音量
public SeekBar soundBar;
private int maxVolume, currentVolume;

private int volume=0; //初始化声音

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mediaPlayer01 = new MediaPlayer();

imageButton_white1=(ImageButton)findViewById(R.id.white1);
final SeekBar soundBar=(SeekBar)findViewById(R.id.sound); //音量设置
mVolume = (TextView)findViewById(R.id.mVolume);
audiomanage = (AudioManager)getSystemService(Context.AUDIO_SERVICE);

maxVolume = audiomanage.getStreamMaxVolume(AudioManager.STREAM_MUSIC); //获取系统最大音量
soundBar.setMax(maxVolume); //拖动条最高值与系统最大声匹配
currentVolume = audiomanage.getStreamVolume(AudioManager.STREAM_MUSIC); //获取当前值
soundBar.setProgress(currentVolume);
mVolume.setText(currentVolume*100/maxVolume + " %");

soundBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() //调音监听器
{
public void onProgressChanged(SeekBar arg0,int progress,boolean fromUser)
{
audiomanage.setStreamVolume(AudioManager.STREAM_MUSIC, progress, 0);
currentVolume = audiomanage.getStreamVolume(AudioManager.STREAM_MUSIC); //获取当前值
soundBar.setProgress(currentVolume);
mVolume.setText(currentVolume*100/maxVolume + " %");
}

@Override
public void onStartTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub

}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub

}
});

TextView的XML没有给出,需要自己添加。

⑸ androd中怎么替换android seekbar 刻度的系统滑块图标

android:thumb

用这个属性,传一个Drawable

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

阅读全文

与androidseekbar样式相关的资料

热点内容
sha1withrsa算法 浏览:453
域名交易系统源码php 浏览:171
求解微分方程数值解的命令有哪些 浏览:626
程序员转时尚传媒 浏览:82
古拳谱pdf 浏览:42
一元二次方程无实数根的算法 浏览:352
程序员测试轻松吗 浏览:170
英雄联盟神魔怎么绑定服务器 浏览:982
音乐app怎么换音质 浏览:974
python进阶客户流失 浏览:280
华为荣耀10服务器地址 浏览:998
javastring相等判断 浏览:411
程序员考研究生学校 浏览:935
java卡顿 浏览:500
编程软件怎么运行zip文件 浏览:505
单片机怎么做组态 浏览:899
android参考文献外文 浏览:684
铜电极电流效率的算法 浏览:142
短信内存已满怎么处理安卓 浏览:314
ogg命令 浏览:785