首先,我将为您的内部relativelayout分配一个id:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/container"
>
现在我可以在代码中引用RelativeLayout,我将添加一个新字段:
ProgressBar progressBar;
RelativeLayout container;
然后 onClick 我将隐藏您的容器:
@Override public void onClick(View view) {
progressBar.setVisibility(View.VISIBLE);
container.setVisibility(View.GONE); ...
并在任务完成后使其可见:
@Override public void onResponse(String response) {
try {
JSONObject jsonObject = new JSONObject(response);
boolean result = jsonObject.getBoolean("register_result");
progressBar.setVisibility(View.GONE);
container.setVisibility(View.VISIBLE);...
希望能帮助到你。
但是,我不会推荐所有应用程序中的用户体验。还有其他机制通知用户,检查材料设计指南(下):
进展和活动:https://material.io/archive/guidelines/components/progress-activity.html# https://material.io/archive/guidelines/components/progress-activity.html#进度指标:https://material.io/components/progress-indicators https://material.io/components/progress-indicators
顺便说一句,我测试了代码,它的工作方式正如您提到的那样。这是代码的要点,但是如果您使用代码片段会更好,因为我重命名了几个变量:
https://gist.github.com/moxi/396b073f9df063dc3c943579c93f1be9 https://gist.github.com/moxi/396b073f9df063dc3c943579c93f1be9
查看此 gif 上的结果:https://giphy.com/gifs/uAAYE6j9hy6dy https://giphy.com/gifs/uAAYE6j9hy6dy