【发布时间】:2014-06-21 15:04:09
【问题描述】:
我一直在我的应用程序的片段中添加ProgressBar。我已将其设置为两个主要片段(用作选项卡),如下所示:
ProgressBar in activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ProgressBar
android:id="@+id/progressBar1"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true" />
</RelativeLayout>
设置ProgressBarVISIBLE和GONE:
spinner = (ProgressBar)getActivity().findViewById(R.id.progressBar1);
spinner.setVisibility(View.VISIBLE);
spinner.setVisibility(View.GONE);
这没有任何问题。我尝试将另一个ProgressBar 添加到另一个具有WebView 的片段中:
ProgressBar in fragment_article.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="info.androidhive.slidingmenu.ArticleFragment$PlaceholderFragment" >
<WebView android:id="@+id/webPage"
android:layout_height="wrap_content"
android:layout_width="wrap_content"/>
<ProgressBar
android:id="@+id/progressBar1"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true" />
</RelativeLayout>
设置可见性:
spinner = (ProgressBar)getActivity().findViewById(R.id.progressBar1);
spinner.setVisibility(View.VISIBLE);
spinner.setVisibility(View.GONE);
设置可见性的方式与前面的代码相同,但由于某种原因,这不是将ProgressBar 设置为GONE。不知道怎么回事。
我已经尝试使用clearAnimation,这里建议Android, setVisbility to gone not working in RelativeLayout,但仍然没有。
spinner.clearAnimation();
spinner.setVisibility(View.GONE);
【问题讨论】:
-
尝试将 id 更改为 R.id.progressBar2
-
感谢您的建议,作为@Illegal Argument 的回答,我使用的是
getActivity而不是viewInflated
标签: android android-fragments progress-bar android-spinner