所以当我点击一个活动,我想显示一个加载gif,而不是一个:' progresessdialog ',但我怎么能把这个在屏幕的中心和前面不替换其他对象?
<FrameLayout
android:id="@+id/scrim"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/dark_translucent"
android:visibility="gone">
<ImageView
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="24dp"/>
</FrameLayout>
</FrameLayout>
添加到build.gradle(Module.app)
dependencies {
compile 'com.github.bumptech.glide:glide:3.6.1'
}
In your Activity
Glide.with(this)
.load(imageGif)
.asGif()
.fitCenter()
.crossFade()
.into(imageView);
有一个很好的库,叫做android -gif-drawable
在将库添加到项目后,您可能希望这样做:
<pl.droidsonroids.gif.GifImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_gravity="center"
android:src="@drawable/src_drawable_here"
/>
确保它位于一个允许父元素居中的布局中(这意味着水平和垂直居中),例如RelativeLayout。
我是这样做的:
<FrameLayout> <!-- this can also be a CoordinatorLayout -->
... (content)
<FrameLayout
android:id="@+id/scrim"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/dark_translucent"
android:visibility="gone">
<ProgressBar
android:id="@+id/progressBar"
style="@style/Widget.AppCompat.ProgressBar.Horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="24dp"
android:indeterminate="true"/>
</FrameLayout>
</FrameLayout>
与加载器一起使用。当加载程序启动时,我将脚本可见性设置为visible
。加载完成后,我将脚本可见性设置回gone
。
:
您应该跟踪在保存的实例状态下scrim是否可见,因此,如果用户在加载程序正在进行时旋转设备,您可以立即在
onCreate
中再次显示scrim。如果你正在覆盖可触控控件,你应该让所有的控件禁用,直到完成。或者,你可以在脚本布局上设置
onTouchListener
来使用触摸事件,从而有效地禁用内容控件。