ProgressDialog在某些机型上显示不正常。

用HTC的手机,装小米的系统。系统版本为2.3.7android。它的进度条没有全屏居中显示,并且自带橘红色的旋转圈圈,背景自带的为黑色。
解决方法如下:
pd = new ProgressDialog(context);
pd.setCanceledOnTouchOutside(false);
pd.setCancelable(true);
pd.setOnCancelListener(new DialogInterface.OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
context.finish();
}
});
pd.show();
pd.setContentView(R.layout.progress_bar); //自定义布局
pd.getWindow().setGravity(Gravity.CENTER);   //进度条show()了之后,再调整居中显示
pd.getWindow().setBackgroundDrawableResource(R.color.transparent);//进度条show()了之后,再将背景设置为透明


progress_bar,自定义的布局。
<ProgressBar xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:background="@color/transparent"
    android:indeterminateDrawable="@drawable/progressbar"   //规定进度条 形状以及颜色
    >
</ProgressBar>
progressbar.xml 如下:
<?xml version="1.0" encoding="utf-8"?>
<animated-rotate xmlns:android="http://schemas.android.com/apk/res/android"
    android:fromDegrees="0"
    android:pivotX="50%"
    android:pivotY="50%"
    android:toDegrees="360" >


    <shape
        android:innerRadiusRatio="3.5"    
        android:shape="ring"
        android:thicknessRatio="15"    
        android:useLevel="false" >
        <gradient
            android:centerColor="@color/font_gray"   //灰色
            android:centerY="0.50"
            android:endColor="@color/font_darkgray" //灰色
            android:startColor="@color/font_lightgray" //灰色
            android:type="sweep"
            android:angle="45"
            android:useLevel="false" />
    </shape>


</animated-rotate>
关于圈圈的形状,此处要求环的半径较大,环的厚度很薄。注意:
android:innerRadiusRatio 浮点型,以环的宽度比率来表示内环的半径,
  例如,如果android:innerRadiusRatio,表示内环半径等于环的宽度除以5,这个值是可以被覆盖的,默认为9.
值越小,半径越大。


android:thicknessRatio 浮点型,以环的宽度比率来表示环的厚度,例如,如果android:thicknessRatio="2",
  那么环的厚度就等于环的宽度除以2。这个值是可以被android:thickness覆盖的,默认值是3.
值越大,厚度越薄。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值