这是我的 xml 文件:
<ProgressBar
android:id="@+id/progress_index"
style="@android:style/Widget.ProgressBar.Inverse"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:visibility="gone"/>
<ListView
android:id="@+id/listview_index"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbarStyle="outsideInset">
</ListView>
我尝试在 mListView.setAdapter()
之后 mProgress.setVisibility(View.GONE)
,但是当我在“开发者选项”中选中“显示布局边界”时".布局实际上并没有消失。如图所示,ProgressBar 仍然位于 FrameLayout 的中心。为什么?
Java代码:
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
mProgress = (ProgressBar) view.findViewById(R.id.progress_index);
mProgress.setVisibility(View.VISIBLE);
mAdapter = new CustomAdapter(getActivity());
new MyTask().execute();
lv.setAdapter(mAdapter);
}
public class MyTask extends AsyncTask<Integer, Void, ArrayList<NewsItem>> {
protected ArrayList<NewsItem> doInBackground(Integer... params) {
// some execution....
}
protected void onPostExecute(ArrayList<NewsItem> result) {
mAdapter.notifyDataSetChanged();
mProgress.setVisibility(View.GONE);
mListView.setVisibility(View.VISIBLE);
}
}
最佳答案
你能试试这个吗:
ProgressDialog mProgress = new ProgressDialog(activity.this);
...........
mProgress.dismiss();
关于android - 为什么 ProgressBar 没有消失?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23149609/