自定义圆形滚动条(在自定义标题栏中显示)--利用开源项目ProgressWheel(二)
来源:互联网 发布:吉首大学网络缴费 编辑:程序博客网 时间:2024/06/07 15:50
本篇是ProgressWheel使用的第二篇(尾篇),功能是在自定义标题栏中显示ProgressWheel滚动条。
本篇引用的开源项目依然是ProgressWheel,地址:
https://github.com/Todd-Davies/ProgressWheel本篇代码下载地址:
android-async-http progress-wheel测试程序本篇效果图:
自定义滚动条(在自定义标题栏中显示)的实现:
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 0
- 自定义圆形滚动条(在自定义标题栏中显示)--利用开源项目ProgressWheel(二)
- 自定义圆形滚动条(透明效果)--利用开源项目ProgressWheel
- 自定义圆形滚动条(透明效果)--利用开源项目ProgressWheel
- Android中自定义标题栏(二)
- Android中自定义圆形图片(二)
- 去掉窗体滚动条,并在自定义DIV中显示垂直滚动条
- 在WPF中自定义滚动条
- 自定义圆形进度条(二)
- 如何一直显示tableview的滚动条(自定义方法)
- CSS在移动端隐藏滚动条/自定义滚动条(scrollbar的各种属性)
- HTML自定义滚动条(仿网易邮箱滚动条)
- 自定义动态圆形ProgressBar_(二)
- 自定义圆形加载条
- 在各浏览器中自定义滚动条样式
- android自定义滚动条(ScrollBar)样式
- 【JQuery】HTML自定义滚动条(mCustomScrollbar)
- UIScrollview一直显示滚动条,使用UIImageView自定义滚动条
- 自定义Toaster,显示在标题栏底部
- Xmpp工具
- leetcode 207: Course Schedule
- Cuda中Global memory中coalescing例程解释
- Leetcode NO.187 Repeated DNA Sequences
- JavaScript用途
- 自定义圆形滚动条(在自定义标题栏中显示)--利用开源项目ProgressWheel(二)
- 图形化界面编程
- 天龙网游入师门拿福利 师门系统讲解
- 竹杖芒鞋轻胜马,一蓑烟雨任平生——写在38岁生日
- leetcode 212: Word Search II
- SpringAOP(二) 利用动态代理实现横切逻辑
- linux系统CentOS下调整home和root区大小
- AspNet MVC4 教学-16:Asp.Net MVC4 Session及Cookie快速比较Demo
- Sqlsever因实例....问题登不上去时&&在tomcat说端口占用时即查看端口占用方法