2014-03-29 21 views
-1

我正在開發一個使用.gif文件的應用程序。
我發現了很多衝浪後如何在Android中實現gif,但現在的問題是我無法在中心對齊gif。 我嘗試過使用重力作爲中心,但它沒用。如何使gif文件出現在屏幕的中心

任何人都可以幫助我嗎?

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:components="http://schemas.android.com/apk/lib/com.sample.hello" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" 
    xmlns:android="http://schemas.android.com/apk/res/android"> 

    <com.sample.hello.GIFView   
     android:layout_width="200dp" 
     android:layout_height="200dp" 
     android:layout_gravity="center" 
     components:src="@drawable/gifid" 
    /> 
</LinearLayout> 

回答

1

使用相對佈局而不是線性,並將center_vertical和center_horizo​​ntal置於圖像上的true。

+0

更好地利用:'機器人:layout_centerInParent =「真」'(一個屬性,而不是二) –

+0

好點,我忘了該屬性。 –

+0

它發生在最偉大的...;) –

2

使用此佈局,以中心您的GIF在屏幕上

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 
    xmlns:components="http://schemas.android.com/apk/lib/com.sample.hello" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" xmlns:android="http://schemas.android.com/apk/res/android" 
    > 
    <com.sample.hello.GIFView 
     android:layout_width="200dp" 
     android:layout_height="200dp" 
     android:layout_gravity="center" 
     android:layout_centerInParent="true" 
     components:src="@drawable/gifid" 
    /> 
</RelativeLayout> 
相關問題