![](/img/trans.png)
[英]How to make a custom ProgressDialog Android? (Not cleaned dimensions of a standard ProgressDialog)
[英]Positioning Custom ProgressDialog Android
我已经制作了一个透明的自定义进度条,我希望以编程方式将进度条移动到屏幕上的某个位置,但是每次在屏幕中间绘制自定义进度条时。
public class CustomProgressBar extends Dialog {
ProgressBar mProgressBar;
TextView mTextMessage;
public CustomProgressBar(Context context, int id) {
super(context, R.style.ProgressDialogTheme);
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.custom_progree_dialog,
null);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
params.addRule(RelativeLayout.ALIGN_PARENT_LEFT);//the progress bar does not get aligned to left top with the defined margin space.
params.addRule(RelativeLayout.ALIGN_PARENT_TOP);//
params.setMargins(50, 50, 0, 0);//
// layoutParams.addRule(RelativeLayout.ALIGN_PARENT_TOP, id);
this.addContentView(view, params);
}
}
这就是我在活动中使用它的方式
Dialog mProgressBar = new CustomProgressBar(
MyActivity.this,
otherView.getId());
我的进度条布局文件custom_progree_dialog.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<ProgressBar
android:id="@+id/id_server_connection_progress_dialog"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:indeterminateDrawable="@drawable/somedrwablefile" />
<TextView
android:id="@+id/id_server_connection_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="@dimen/padding_30px"
android:layout_marginTop="@dimen/padding_4px"
android:layout_toRightOf="@id/progress_dialog"
android:text="@string/connectingMessage"
android:textColor="@color/white"
android:textSize="@dimen/padding_40px" />
</RelativeLayout>
请指导我,让我知道我要去哪里。我花了两天的时间来找出问题所在。
因此,我通过更改custom_progress_dialog并将进度条和文本与所需位置对齐来解决了这个问题,而且我不再使用自定义类了,我只是在运行时扩大布局并将其作为子级添加查看我的活动内部。
if (mView == null)
{
mView = getLayoutInflater().inflate(R.layout.server_connection_progree_dialog,null);
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT,RelativeLayout.LayoutParams.WRAP_CONTENT);
MyActivity.this.addContentView(mView, layoutParams);
}
else
if (!mView.isShown())
{
mView.setVisibility(View.VISIBLE);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.