在 android 的工具栏上添加 gif
adding gif on toolbar in android
我是 android 和 java 的新手,我需要一个问题的解决方案,我希望 android 的工具栏中有一个 gif,它总是 运行屏幕出现,我可以使用 koral's library 添加 gif 但我无法弄清楚如何在工具栏中添加此 gif 我在 iOS 中执行此操作并能够在选项卡栏中添加 gif ,我也需要 android 中的相同 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>
使用 notactiontoolbar
并在您的布局中添加自定义 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>
您可以通过 Glide 显示 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>
Java代码:
Glide.with(this).load(R.drawable.test_gif).asGif().into(imageViewGIF);
预览:
我是 android 和 java 的新手,我需要一个问题的解决方案,我希望 android 的工具栏中有一个 gif,它总是 运行屏幕出现,我可以使用 koral's library 添加 gif 但我无法弄清楚如何在工具栏中添加此 gif 我在 iOS 中执行此操作并能够在选项卡栏中添加 gif ,我也需要 android 中的相同 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>
使用 notactiontoolbar
并在您的布局中添加自定义 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>
您可以通过 Glide 显示 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>
Java代码:
Glide.with(this).load(R.drawable.test_gif).asGif().into(imageViewGIF);
预览: