android两个屏幕交互,android-如何实现加载屏幕以防止用户在进行后台处理时与界面进行交互...

在我的新应用中,我需要在进行一些处理时显示动画(例如,将数据发送到服务器,从Web服务读取数据等).

像这样:

c7f80193403eb4e691bbca59ed6bcf55.png

当我想实现类似的东西时,这就是我曾经做过的事情:

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical" >

android:id="@+id/sincronizarSpinnerLayout"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:visibility="gone" >

android:id="@+id/pbHeaderProgress"

style="@android:style/Widget.ProgressBar.Inverse"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_centerInParent="true" >

如您所见,我有两个嵌套的相对布局.默认情况下,第一个布局是不可见的(android:visibility =“ gone”),并且只有在启动Service,AsyncTask或异步技术时才使它可见.

尽管我过去曾经使用过这种方法,但是现在我的主布局(应该放在第二个相对布局内)更加复杂,但我不确定使事情变得更加复杂不是一个好主意.为我的活动添加另一个嵌套级别.

>有什么方法可以避免必须为所有其他布局添加其他布局

我需要显示微调动画的活动?也许

我不知道有某种模式或良好做法.

>我真的需要担心为我的图层添加另一个嵌套级别吗

活动,知道我已经有两个或三个级别?

谢谢.

解决方法:

您可以简单地使用ProgressDialog并使用setCanceledOnTouchOutside(false),以便在AsyncTask工作时用户无法触摸外部.

这是我在使用AsyncTask的项目中几乎使用的结构代码.您可以申请您的项目:

public class DownloadTask extends AsyncTask {

private ProgressDialog mProgressDialog;

private Context mContext;

public DownloadTask(Context context) {

this.mContext = context;

}

@Override

protected void onPreExecute() {

super.onPreExecute();

mProgressDialog = ProgressDialog.show(mContext, "Downloading", "Downloading Data ...");

mProgressDialog.setCanceledOnTouchOutside(false); // main method that force user cannot click outside

mProgressDialog.setCancelable(true);

mProgressDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {

@Override

public void onCancel(DialogInterface dlg) {

DownloadTask.this.cancel(true);

}

});

}

@Override

protected Void doInBackground(Void... params) {

// do some background work here

}

@Override

protected void onPostExecute(Void result) {

if (this.isCancelled()) {

result = null;

return;

}

if (mProgressDialog != null) {

mProgressDialog.dismiss();

}

}

}

希望这个帮助:)

标签:performance,android-layout,android

来源: https://codeday.me/bug/20191027/1944330.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值