2016-11-17 69 views

回答

0
<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' 
} 

在你的活動

Glide.with(this) 
      .load(imageGif) 
      .asGif() 
      .fitCenter() 
      .crossFade() 
      .into(imageView); 
+1

謝謝,但我已經找到了答案。 – sander

+0

只是一些聲譽 – sander

+0

@sander感謝男人:) –

0

有這個極好的庫調用andorid-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。

+0

我已經使用這一個,但在第1頁我由於它使用了多個佈局,因此遇到了一些麻煩。 – sander

+0

我發現你需要使用:'FrameLayout'。 – sander

0

這是我要做的事:

<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

有兩件事情:

  • 你應該跟蹤該紗幕是否可見或不可見在保存實例的狀態,因此,如果用戶旋轉設備,同時裝載過程中,您可以顯示網格布再次立即在onCreate

  • 如果您要覆蓋可觸摸的控件,則應該禁用所有控件直至完成。或者,您可以在網格佈局上設置onTouchListener以消耗觸摸事件,以便有效禁用內容控件。

+0

感謝您的反饋。我已經有了一個選項(對不起),但是我有一些麻煩,因爲我想讓它在AsyncTask類中可見,但我看不到它。 – sander