Android 中的 seekBar会被开发者经常用到,用的最多的空拍是控制音量。但是有时后为了更好的UI效果,横着的拖动条不能满足我们项目的需要,我们可能需要竖直的或者圆形的拖动条,那这两种样式的类SeekBar的效果如何实现呢,接下来小编会一一给出效果和源码。接下来,先说一说圆形的效果吧,有图有真相,请看图:
看过图之后是不是觉得很炫,自己赞一个,下面给出源码:
/values/attr.xml:
[html] view
plain
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable>
<attr format="integer" />
<attr format="integer" />
<attr format="integer"></attr>
<attr format="boolean"></attr>
<attr format="integer"></attr>
<attr format="integer"></attr>
<attr format="integer"></attr>
<attr format="integer"></attr>
<attr format="string"></attr>
<attr format="string"></attr>
<attr format="string"></attr>
<attr format="string"></attr>
<attr format="string"></attr>
<attr format="string"></attr>
</declare-styleable>
</resources>
ZJBCircleSeekBar.java:
[java] view
plain
package com.example.circleseekbar;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.SweepGradient;
import android.os.Bundle;
import android.os.Parcelable;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
/**
* @author zjbpku
* @time 2013-08-21
* @blog
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center_horizontal"
tools:context=".MainActivity" >
<TextView
android:id="@+id/text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="80dp"
android:gravity="center_horizontal"
android:textSize="60sp"
android:textColor="#ffff0000"
/>
<com.example.circleseekbar.HoloCircleSeekBar
android:id="@+id/c"
android:layout_width="500px"
android:layout_height="500px"
android:layout_centerInParent="true" />
</RelativeLayout>
MainActivity.java:
[java] view
plain
package com.example.circleseekbar;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
import com.example.circleseekbar.ZJBCircleSeekBar.OnCircleSeekBarChangeListener;
/**
* @author zjbpku
* @time 2013-08-21
* @blog
*/
public class MainActivity extends Activity implements
OnCircleSeekBarChangeListener {
private ZJBCircleSeekBar circleSeekBar;
TextView textView;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
circleSeekBar = (ZJBCircleSeekBar) findViewById(R.id.c);
textView = (TextView) findViewById(R.id.text);
circleSeekBar.setOnSeekBarChangeListener(this);
}
@Override
public void onProgressChanged(ZJBCircleSeekBar seekBar, int progress,
boolean fromUser) {
// TODO Auto-generated method stub
textView.setText(progress + "");
}
}
小编很辛苦,请尊重菜鸟的劳动成果,转载请注明出处:/content/525436.html