在android工具栏上添加gif

在android工具栏上添加gif,android,android-toolbar,animated-gif,Android,Android Toolbar,Animated Gif,我不熟悉android和java,我需要一个问题的解决方案,我想在android的工具栏上放一个gif,当屏幕显示时,它总是在运行,我可以使用添加gif,但我不知道如何在工具栏中添加gif我在iOS中做了这件事,可以在选项卡栏中添加gif,我在android中也需要相同的gif, 这是我真正想要的,任何帮助都会被感激的 像这样创建自定义工具栏布局。并把你的gif、标题等放在这里 <android.support.v7.widget.Toolbar xmlns:android="http:/

我不熟悉android和java,我需要一个问题的解决方案,我想在android的工具栏上放一个gif,当屏幕显示时,它总是在运行,我可以使用添加gif,但我不知道如何在工具栏中添加gif我在iOS中做了这件事,可以在选项卡栏中添加gif,我在android中也需要相同的gif, 这是我真正想要的,任何帮助都会被感激的


像这样创建自定义工具栏布局。并把你的gif、标题等放在这里

<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:minHeight="?attr/actionBarSize"
    android:theme="@style/AppTheme.AppBarOverlay"
    app:popupTheme="@style/AppTheme.PopupOverlay">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <pl.droidsonroids.gif.GifImageView
           android:layout_width="match_parent"
           android:layout_height="match_parent"
           android:src="@drawable/src_anim"
           android:background="@drawable/bg_anim"/>

        //Other views

    </RelativeLayout>

</android.support.v7.widget.Toolbar>

//其他观点

使用
注释工具栏
并在布局中添加自定义
工具栏
,这样您可以在工具栏标记中添加任何子项,例如,使用imageview和kroals lib或glid在该imageview中设置gif 以下来源将帮助您理解

 <android.support.v7.widget.Toolbar
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/colorPrimaryDark">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        tools:layout_editor_absoluteX="16dp">

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:src="@mipmap/ic_launcher" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_centerVertical="true"
            android:text="Home"
            android:textAppearance="@style/Base.TextAppearance.AppCompat.Large"
            android:textColor="#fff" />

    </RelativeLayout>


</android.support.v7.widget.Toolbar>

您可以通过显示gif图像,这是Android的图像加载和缓存库

XML代码:

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="@color/green"
        app:titleTextColor="@color/white" >

        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

        <ImageView
            android:id="@+id/ivtest"
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:layout_gravity="end"/>
        </FrameLayout>

    </android.support.v7.widget.Toolbar>
    Glide.with(this).load(R.drawable.test_gif).asGif().into(imageViewGIF);
预览:

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="@color/green"
        app:titleTextColor="@color/white" >

        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

        <ImageView
            android:id="@+id/ivtest"
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:layout_gravity="end"/>
        </FrameLayout>

    </android.support.v7.widget.Toolbar>
    Glide.with(this).load(R.drawable.test_gif).asGif().into(imageViewGIF);