我有这样一个布局:
<?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 方法中,我首先执行以下操作来隐藏 ProgressBar:
LayoutInflater inflater = getLayoutInflater();
RelativeLayout layout = (RelativeLayout)inflater.inflate(R.layout.achievements_screen, null);
progressBar=(ProgressBar)layout.findViewById(R.id.aPBar);
progressBar.setVisibility(View.INVISIBLE);
但是进度条始终可见...我也尝试过使用View.GONE。当我设置:
android:visible="gone"
在XML文件中,
ProgressBar
没有显示出来,但我无法使其出现。 progressBar.setVisibility(View.Visible);
progressBar=(ProgressBar)findViewById(R.id.aPBar);
而不是progressBar=(ProgressBar)layout.findViewById(R.id.aPBar);
使其工作了,但我不知道为什么会起作用。在super.onCreate
和setContentView
之后,在我的活动的onCreate
中添加了此布局视图。 - yon