自定义圆形滚动条(在自定义标题栏中显示)

本篇是ProgressWheel使用的第二篇(尾篇),功能是在自定义标题栏中显示ProgressWheel滚动条。

本篇引用的开源项目依然是ProgressWheel,地址: https://github.com/Todd-Davies/ProgressWheel

本篇效果图:

自定义滚动条(在自定义标题栏中显示)的实现:

1)activity_progress_wheel_test. xml:<RelativeLayout xmlns:android=”http://schemas.android.com/apk/res/android”xmlns:tools=”http://schemas.android.com/tools”android:layout_width=”match_parent”android:layout_height=”match_parent”android:paddingBottom=”@dimen/activity_vertical_margin”android:paddingLeft=”@dimen/activity_horizontal_margin”android:paddingRight=”@dimen/activity_horizontal_margin”android:paddingTop=”@dimen/activity_vertical_margin”android:background=”@color/white”tools:context=”.ProgressWheelTestActivity” ><TextViewandroid:layout_width=”wrap_content”android:layout_height=”wrap_content”android:text=”@string/hello_world” /></RelativeLayout>2) titlebar_detail.xml:<?xml version=”1.0″ encoding=”utf-8″?><RelativeLayout xmlns:android=”http://schemas.android.com/apk/res/android”xmlns:ProgressWheel=”http://schemas.android.com/apk/res-auto”android:layout_width=”fill_parent”android:layout_height=”fill_parent”android:orientation=”horizontal”android:background=”@color/blue” ><ImageViewandroid:id=”@+id/imageview_back”android:layout_width=”wrap_content”android:layout_height=”wrap_content”android:layout_centerVertical=”true”android:src=”@drawable/ic_launcher” /><TextViewandroid:id=”@+id/textview_middle”android:layout_width=”wrap_content”android:layout_height=”wrap_content”android:layout_centerInParent=”true”android:text=”@string/home”android:textColor=”@color/white”android:textSize=”18sp” /><com.todddavies.components.progressbar.ProgressWheelandroid:id=”@+id/progressBar”android:layout_width=”46dp”android:layout_height=”46dp”android:layout_alignParentRight=”true”android:layout_centerVertical=”true”ProgressWheel:barColor=”#0097D6″ProgressWheel:barLength=”30dp”ProgressWheel:barWidth=”5dp”ProgressWheel:contourColor=”#330097D6″ProgressWheel:rimColor=”@color/white”ProgressWheel:rimWidth=”5dp”ProgressWheel:spinSpeed=”10dp”ProgressWheel:text=”0/0″ProgressWheel:textColor=”#FFFFFF”ProgressWheel:textSize=”12sp”android:visibility=”gone”/><ImageViewandroid:id=”@+id/imageView_Right”android:layout_width=”wrap_content”android:layout_height=”wrap_content”android:layout_alignParentRight=”true”android:layout_centerVertical=”true”android:layout_marginRight=”5dp”android:src=”@drawable/search_normal”/></RelativeLayout>3)自定义的styles:(在styles文件中): <!– customer define. –><style name=”CustomWindowTitleBackground”><item name=”android:background”>@color/honeydew</item></style><style name=”test” parent=”android:Theme”><item name=”android:windowTitleSize”>48dp</item><item name=”android:windowTitleBackgroundStyle”>@style/CustomWindowTitleBackground</item></style>4). java代码:ProgressWheelTestActivity.javapackage com.example.progresswheeltest;import com.todddavies.components.progressbar.ProgressWheel;import android.os.Bundle;import android.os.Handler;import android.os.Message;import android.app.Activity;import android.content.Context;import android.view.Menu;import android.view.View;import android.view.View.OnClickListener;import android.view.Window;import android.widget.ImageView;import android.widget.Toast;{ProgressWheel mProgressWheel =null;private ImageView imageView_Right;private Context mContext;(Bundle savedInstanceState) {super.onCreate(savedInstanceState);requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);setContentView(R.layout.activity_progress_wheel_test);getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,R.layout.titlebar_detail);//init layoutImageView imageView_Back = (ImageView)findViewById(R.id.imageview_back);imageView_Back.setOnClickListener(new OnClickListener(){(View arg0) {Toast.makeText(mContext, “left icon is pressed!”, Toast.LENGTH_LONG).show();}});mProgressWheel = (ProgressWheel)findViewById(R.id.progressBar);mProgressWheel.setVisibility(View.GONE);imageView_Right = (ImageView)findViewById(R.id.imageView_Right);imageView_Right.setVisibility(View.GONE);//start teststartTestHandler();}(Menu menu) {// Inflate the menu; this adds items to the action bar if it is present.getMenuInflater().inflate(R.menu.progress_wheel_test, menu);return true;}() {if (mProgressWheel != null) {mProgressWheel.setVisibility(View.VISIBLE);mProgressWheel.spin();}}() {if (mProgressWheel != null) {mProgressWheel.stopSpinning();mProgressWheel.setVisibility(View.GONE);}// show right iconif (imageView_Right != null) {imageView_Right.setVisibility(View.VISIBLE);}}(String text) {if (mProgressWheel != null) {mProgressWheel.setText(text);}}() {mMyHandler.start();}MyHandler mMyHandler = new MyHandler();{public int loop = 0;MyHandler() {}() {showProgressWheel();sendEmptyMessage(200);}(Message msg) {if (msg.what == 200) {startTestThread();}else if (msg.what == 300) {//errorcloseProgressWheel();}else if (msg.what == 0){//结束closeProgressWheel();}}}() {new Thread(new Runnable() {() {try {Thread.sleep(3000);} catch (Exception e) {e.printStackTrace();}mMyHandler.loop++;if (mMyHandler.loop<5) {setProgressWheelText(“” + mMyHandler.loop + “http://blog.csdn.net/” + 5);mMyHandler.sendEmptyMessage(200);}else {//结束时,发送300mMyHandler.sendEmptyMessage(300);}}}).start();}}5)说明:1. 需要导入ProgressWheel jar包或者以library的方式导入到项目中;2. 自定义titlebar的实现(注意加载完成后右边的图片会更新);3. 请区别本博ProgressWheel 使用的第一篇的实现方式,,第一篇用的是静态的方式实现的。

开源的力量是无穷的!

也和他共度。甚至连吵架也是重复的,

自定义圆形滚动条(在自定义标题栏中显示)

相关文章:

你感兴趣的文章:

标签云: