【问题标题】:ContentLoadingProgressBar is never showsContentLoadingProgressBar 从不显示
【发布时间】:2014-03-09 09:59:34
【问题描述】:

我已将片段中的简单ProgressBar 替换为ContentLoadingProgressBar。 现在片段布局看起来像这样:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
            style="@style/simple_match_parent_style">

<android.support.v4.widget.ContentLoadingProgressBar
            android:id="@+id/progress"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"/>

<TextView
    android:id="@+id/txt_no_songs"
    android:text="@string/txt_no_songs"
    android:layout_centerInParent="true"
    style="@style/txt_no_songs"/>

<ListView
    android:id="@+id/list"
    android:fastScrollEnabled="true"
    android:divider="@null"
    style="@style/simple_match_parent_style"/>

</RelativeLayout>

我在onViewCreated中显示这个ProgressBar:

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    progressBar = (ContentLoadingProgressBar) view.findViewById(R.id.progress);
    progressBar.show();
    ...
}

出于测试目的,我删除了progressBar.hide() 调用以使 ProgressBar 在任何情况下都出现。但问题是我的ContentLoadingProgressBar 从未真正显示出来。

我应该做其他事情来显示ContentLoadingProgressBar吗?我没有找到任何使用ContentLoadingProgressBar 的相关示例,因此也需要任何有用的示例。提前致谢。

【问题讨论】:

  • 你可以在这个链接中找到你想要的东西stackoverflow.com/questions/20438751/…
  • 我看到了这个话题,但我没有发现任何有用的东西
  • 你不能使用progressBar.show();这里。在 onViewCreated() 调用之后,然后调用 ContentLoadingProgressBar.onAttachedToWindow() 查看源代码,他们在这里删除了显示回调。因此,进度条永远不会显示。

标签: android android-progressbar


【解决方案1】:

似乎你需要一种风格,例如...

style="?android:attr/android:progressBarStyleHorizontal"

不管怎样,如果我把它给我工作,我什么都看不到。

也可以考虑把它放在你的内容之上(即在 xml 的下面)

【讨论】:

  • 改成这样就可以了:style="?android:attr/progressBarStyleHorizontal"否则会出现如下编译错误:AAPT: error: resource android:attr/android:progressBarStyleHorizontal not found.
  • 您现在还可以使用更新的样式:style="@style/Widget.AppCompat.ProgressBar.Horizo​​ntal"
【解决方案2】:

我试过这个:

<android.support.v4.widget.ContentLoadingProgressBar
        android:id="@+id/address_looking_up"
        style="?android:attr/android:progressBarStyleHorizontal"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:visibility="visible" />

但是,它不适用于 Android 5.0。有关 ContentLoadingProgressbar 的更多详细信息应该在这里。

PS:好吧,'style' 的属性在这里很重要。将样式更改为“?android:attr/progressBarStyleLarge”即可。

同时,此小部件的显示效果取决于您应用的主题。

【讨论】:

    【解决方案3】:

    1.SDK 表示“等待最小延迟后显示进度视图。如果 在那段时间里,hide() 被调用,视图永远不可见。” 2. 我觉得你的布局应该这样修改:

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
            style="@style/simple_match_parent_style">
    <TextView
    android:id="@+id/txt_no_songs"
    android:text="@string/txt_no_songs"
    android:layout_centerInParent="true"
    style="@style/txt_no_songs"/>
    
    <ListView
    android:id="@+id/list"
    android:fastScrollEnabled="true"
    android:divider="@null"
    style="@style/simple_match_parent_style"/>
    <android.support.v4.widget.ContentLoadingProgressBar
            android:id="@+id/progress"
            android:layout_width="wrap_content"
            style="?android:attr/progressBarStyleLarge"
            android:visibility="gone"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"/>
    </RelativeLayout>
    

    【讨论】:

      【解决方案4】:

      如果您同时创建多个视图,请检查ContentLoadingProgressBar.onAttachedToWindow()ContentLoadingProgressBar.onDetachedToWindow(),这可能会导致private removeCallBacks()onAttachedToWindow()onDetachedToWindow() 中被调用。从而导致runnable无法运行,这意味着什么都不会显示。

      例如,您可以: 只需删除onAttachedToWindow()onDetachedToWindow() 中的private removeCallBacks() 调用即可。为了防止这种情况发生。不要忘记将private removeCallBacks() 设置为public 并在onDestroyView() 中调用以进行适当的清理。

      【讨论】:

        【解决方案5】:

        您应该为 ContentLoadingProgressBar 添加样式。

        <androidx.core.widget.ContentLoadingProgressBar
        android:id="@+id/progress"
        android:layout_width="wrap_content"
        style="?android:attr/progressBarStyleHorizontal"
        android:layout_height="wrap_content"/>
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2012-10-04
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2017-12-05
          • 1970-01-01
          相关资源
          最近更新 更多