【发布时间】:2019-07-30 08:00:00
【问题描述】:
我已经测试了两种在活动上方显示透明加载层(进度条)的方法,但活动内容被隐藏,这是第一个:
<RelativeLayout
android:id="@+id/loadingPanel"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center" >
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:indeterminate="true" />
</RelativeLayout>
还有另一种带有样式的方法
<RelativeLayout
style="@style/GenericProgressBackground"
android:id="@+id/loadingPanel">
<ProgressBar
style="@style/GenericProgressIndicator"/>
</RelativeLayout>
<style name="GenericProgressBackground" parent="android:Theme">
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">fill_parent</item>
<item name="android:background">#DD111111</item>
<item name="android:gravity">center</item>
</style>
<style name="GenericProgressIndicator" arent="@android:style/Widget.ProgressBar.Small">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:indeterminate">true</item>
</style>
隐藏或显示
findViewById(R.id.loadingPanel).setVisibility(View.GONE);
(两者都作为根视图中的第一项添加)
但是这两种方法都隐藏了活动,我希望像下图一样半透明,我该怎么做?
【问题讨论】:
-
为此创建一个自定义对话框。这样它就可以重复使用,您不必担心点击后退按钮。
标签: android animation progress-bar preloading