进度条设置不可行

时间:2012-06-24 19:17:10

标签: android progress-bar

我有这样的布局:

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

但是ProgressBar仍然可见......我也尝试了View.GONE

当我设置

android:visible="gone"

在XML文件中,ProgressBar没有显示,但我无法显示

 progressBar.setVisibility(View.Visible);

3 个答案:

答案 0 :(得分:0)

您正在使用Layout Inflater充气新视图。这是当前屏幕上的视图。

因此,更改其可见性不会影响屏幕UI。

进一步提升您的活动,您必须致电setContentView这是您的用户界面上可见的布局。

因此致电:

findViewById会在屏幕上返回您的进度条,但是调用layout.findViewById会返回该布局进度条(正确),但这不是您可以在屏幕上看到的progressBar。

答案 1 :(得分:0)

这项工作对我来说:

rootView.findViewById(R.id.progress_bar).setVisibility(View.GONE);

答案 2 :(得分:0)

对我来说,解决方法是在XML中隐藏视图,然后在需要时在运行时取消隐藏/隐藏它: android:visibility="gone"