1、实现功能 签到的progress 支持气泡指示器
效果图

%title插图%num
2、实现代码
(1)重写SeekBar禁止拖动
package com.example.demo;
import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.widget.SeekBar;

public class MySeekBar extends SeekBar{

public MySeekBar(Context context) {
super(context,null);
}

public MySeekBar(Context context, AttributeSet attrs) {
super(context, attrs, 0);

}

public MySeekBar(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);

}

@Override
public boolean onTouchEvent(MotionEvent event) {
// TODO Auto-generated method stub
// 原来是要将TouchEvent传递下去的,我们不让它传递下去就行了
// return super.onTouchEvent(event);
return false;
}

}

(2)mainActivity
package com.example.demo;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;

public class MainActivity extends Activity {
private MySeekBar mySeekBar;
private int speed = 0;//进度条每次点击
private int lin_speed = 0;//上面的描述文字的位置
private LinearLayout ll_des;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mySeekBar = (MySeekBar) findViewById(R.id.seekbar);
Button btn_add = (Button) findViewById(R.id.btn_add);
mySeekBar.setProgress(2);
ll_des = (LinearLayout) findViewById(R.id.ll_des);

btn_add.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
runOnUiThread(new Runnable() {
@Override
public void run() {
if (speed == 2) {
speed = 0;
}
if (speed < 68) {
if (speed == 60) {
speed = speed + 10 – 2;//进度条每次前进十个位置
} else {
speed = speed + 10;//进度条每次前进十个位置
}
if (speed <= 60) {
lin_speed = lin_speed + 120;//组件根据实际组件长宽算出来的
}
LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) ll_des.getLayoutParams();
lp.setMargins(lin_speed, 0, 0, 0);
ll_des.setLayoutParams(lp);
mySeekBar.setProgress(speed);
}
}
});
}
});
}

}
(3)布局
<LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android”
android:layout_width=”match_parent”
android:layout_height=”match_parent”
android:layout_gravity=”center_vertical”
android:layout_margin=”30dp”
android:orientation=”vertical”>

<Button
android:id=”@+id/btn_add”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:text=”加” />

<LinearLayout
android:layout_width=”match_parent”
android:layout_height=”80dp”
android:orientation=”vertical”>

<LinearLayout
android:id=”@+id/ll_des”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:layout_marginBottom=”4dp”
android:gravity=”center”
android:orientation=”vertical”>

<TextView
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:background=”@drawable/top_img”
android:paddingBottom=”2dp”
android:paddingLeft=”6dp”
android:paddingRight=”6dp”
android:paddingTop=”2dp”
android:text=”累积18积分”
android:textColor=”#ffffffff”
android:textSize=”9sp” />

<ImageView
android:layout_width=”12dp”
android:layout_height=”wrap_content”
android:src=”@drawable/san_jiao” />
</LinearLayout>

<RelativeLayout
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”>

<ImageView
android:id=”@+id/im_gif”
android:layout_width=”20dp”
android:layout_height=”20dp”
android:layout_marginLeft=”10dp”
android:src=”@drawable/m”
android:visibility=”gone” />

</RelativeLayout>

<com.example.demo.MySeekBar
android:id=”@+id/seekbar”
android:layout_width=”match_parent”
android:layout_height=”wrap_content”
android:layout_gravity=”center”
android:layout_marginTop=”6dp”
android:max=”70″
android:progressDrawable=”@drawable/ddd”
android:thumb=”@drawable/m” />

<LinearLayout
android:layout_width=”match_parent”
android:layout_height=”wrap_content”>

<TextView
style=”@style/myText”
android:text=”@string/_1″ />

<TextView
style=”@style/myText”
android:text=”@string/_2″ />

<TextView
style=”@style/myText”
android:text=”@string/_3″ />

<TextView
style=”@style/myText”
android:text=”@string/_4″ />

<TextView
style=”@style/myText”
android:text=”@string/_5″ />

<TextView
style=”@style/myText”
android:text=”@string/_6″ />

<TextView
style=”@style/myText”
android:text=”@string/_7″ />
</LinearLayout>
</LinearLayout>

</LinearLayout>
(4)核心draeble
<?xml version=”1.0″ encoding=”utf-8″?>
<layer-list xmlns:android=”http://schemas.android.com/apk/res/android”>

<item android:id=”@android:id/background” android:height=”8dp” android:top=”7dp”>
<shape>
<corners android:radius=”@dimen/activity_horizontal_margin”/>
<solid android:color=”#6E8B9B”/>
</shape>
</item>

<item android:id=”@android:id/progress” android:height=”8dp” android:top=”7dp” android:drawable=”@drawable/b”>
</item>

<item android:id=”@android:id/secondaryProgress” android:height=”8dp” android:top=”7dp”>
<clip>
<shape>
<corners android:radius=”@dimen/activity_horizontal_margin”/>
<solid android:color=”#6E8B9B”/>
</shape>
</clip>
</item>

</layer-list>