如何使gif文件出现在屏幕的中心

时间:2014-03-29 14:15:25

标签: android xml apk

我正在开发一个使用.gif文件的应用 我发现如何在经过大量冲浪之后在Android中实现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>

2 个答案:

答案 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>

答案 1 :(得分:1)

使用相对布局而不是线性布局,并在图像上将center_vertical和center_horizo​​ntal设置为true。