Android-ProgressBar setVisibility到GONE无法正常工作 [英] Android - ProgressBar setVisibility to GONE not working

查看:381
本文介绍了Android-ProgressBar setVisibility到GONE无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在我的应用程序的片段中添加ProgressBar.我将其设置为两个主要片段(用作选项卡),如下所示:

I've been adding a ProgressBar to the fragments in my app. I've set it up to the two main fragments (used as tabs) as follows:

ProgressBar:

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

设置ProgressBar VISIBLEGONE:

spinner = (ProgressBar)getActivity().findViewById(R.id.progressBar1);
spinner.setVisibility(View.VISIBLE);

spinner.setVisibility(View.GONE);

这可以正常工作.我试图将另一个ProgressBar添加到另一个具有WebView的片段:

This works without any problems. I've tried to add another ProgressBar to another fragment which has a WebView:

ProgressBar:

<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.不知道怎么了.

Setting the visibility the same way as the previous code but for some reason this is not setting the ProgressBar to GONE. Not sure what's wrong.

我已尝试按照此处建议使用clearAnimation > Android, setVisbility不在RelativeLayout中工作,但仍然没有任何作用.

I've tried using clearAnimation as suggested here Android, setVisbility to gone not working in RelativeLayout but still nothing.

spinner.clearAnimation();
spinner.setVisibility(View.GONE);

推荐答案

检查此代码:

spinner = (ProgressBar)getActivity().findViewById(R.id.progressBar1);

如果您正在使用片段,则应该是这样的:

If you are using fragments it should be like this:

spinner = (ProgressBar)viewIinflated.findViewById(R.id.progressBar1);//same case with dialogs

如果您正在使用活动,则:

If you are using activity then:

spinner = (ProgressBar)findViewById(R.id.progressBar1);

这篇关于Android-ProgressBar setVisibility到GONE无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆