我有這樣一個佈局:進度調用setVisible不工作
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:background="@drawable/menu_background"
>
<ProgressBar
android:id="@+id/aPBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
style="@android:style/Widget.ProgressBar.Inverse"/>
...
</RelativeLayout>
而在我的onCreate方法我這樣做是爲了隱藏進度起初:
LayoutInflater inflater = getLayoutInflater();
RelativeLayout layout = (RelativeLayout)inflater.inflate(R.layout.achievements_screen, null);
progressBar=(ProgressBar)layout.findViewById(R.id.aPBar);
progressBar.setVisibility(View.INVISIBLE);
但ProgressBar
仍然是可見的所有時間...我也試過View.GONE
。
當我在XML文件中設置
android:visible="gone"
,該ProgressBar
犯規露面,但我不能讓它出現與
progressBar.setVisibility(View.Visible);
看起來它應該工作,你可以給一個(ProgressBar)findViewById(R.id.aPBar);' ,而不是'progressBar =(ProgressBar)layout.findViewById(使用增加)這個佈局視圖 –
好吧,我得到它通過使用progressBar = (R.id.aPBar);'但我不知道爲什麼這會起作用。即時將這個佈局視圖添加到super.onCreate和setContentView之後的活動的onCreate中 – yon