为什么ProgressBar没有消失?

时间:2014-04-18 07:35:45

标签: android android-layout

这是我的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>

我在mProgress.setVisibility(View.GONE)之后尝试mListView.setAdapter(),但是当我检查&#34;显示布局边界&#34;在&#34;开发人员选项&#34;。布局实际上没有消失。如图所示,ProgressBar仍然在FrameLayout的中心。为什么?

enter image description here

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);
    }
}

1 个答案:

答案 0 :(得分:2)

你可以试试这个:

 ProgressDialog mProgress  = new ProgressDialog(activity.this);
 ........... 
 mProgress.dismiss();