自定义圆形滚动条(在自定义标题栏中显示)--利用开源项目ProgressWheel(二)

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

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

    本篇代码下载地址:
    android-async-http progress-wheel测试程序

  2. 本篇效果图:
    这里写图片描述]![这里写图片描述

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

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

    <TextView
        android: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" >

    <ImageView
        android:id="@+id/imageview_back"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:src="@drawable/ic_launcher" />

    <TextView
        android: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.ProgressWheel
        android: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"
         />

    <ImageView
        android: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.java

package 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;

public class ProgressWheelTestActivity extends Activity {

    ProgressWheel mProgressWheel =null;
    private ImageView imageView_Right;
    private Context mContext;

    @Override
    protected void onCreate(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 layout
        ImageView imageView_Back = (ImageView)findViewById(R.id.imageview_back);
        imageView_Back.setOnClickListener(new OnClickListener(){

            @Override
            public void onClick(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 test
        startTestHandler();


    }

    @Override
    public boolean onCreateOptionsMenu(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;
    }

    // //progress wheel//
    private void showProgressWheel() {
        if (mProgressWheel != null) {
            mProgressWheel.setVisibility(View.VISIBLE);
            mProgressWheel.spin();
        }
    }

    private void closeProgressWheel() {
        if (mProgressWheel != null) {
            mProgressWheel.stopSpinning();
            mProgressWheel.setVisibility(View.GONE);
        }

        // show right icon
        if (imageView_Right != null) {
            imageView_Right.setVisibility(View.VISIBLE);
        }
    }

    private void setProgressWheelText(String text) {
        if (mProgressWheel != null) {
            mProgressWheel.setText(text);
        }
    }

    //for test thread /
    private void startTestHandler() {
        mMyHandler.start();
    }

    MyHandler mMyHandler = new MyHandler();
    private class MyHandler extends Handler {
        public int loop = 0;
        MyHandler() {
        }


        public void start() {
            showProgressWheel();
            sendEmptyMessage(200);
        }

        @Override
        public void handleMessage(Message msg) {

            if (msg.what == 200) {

                startTestThread();
            }else if (msg.what == 300) {
                //error
                closeProgressWheel();
            }else if (msg.what == 0){
                //结束
                closeProgressWheel();
            }

        }
    }

    /// for test thread,用thread来模拟
    private void startTestThread() {
        new Thread(new Runnable() {
            @Override
            public void run() {

                try {
                    Thread.sleep(3000);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                mMyHandler.loop++;
                if (mMyHandler.loop<5) {
                    setProgressWheelText("" + mMyHandler.loop + "/" + 5);
                    mMyHandler.sendEmptyMessage(200);
                }else {
                    //结束时,发送300
                    mMyHandler.sendEmptyMessage(300);
                }

            }

        }).start();

    }
}

5)说明:

1. 需要导入ProgressWheel jar包或者以library的方式导入到项目中;
2. 自定义titlebar的实现(注意加载完成后右边的图片会更新);
3. 请区别本博ProgressWheel 使用的第一篇的实现方式,第一篇用的是静态的方式实现的。

开源的力量是无穷的!

代码下载:
android-async-http progress-wheel测试程序

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

liranke

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值