【问题标题】:adding gif on toolbar in android [closed]在android的工具栏上添加gif [关闭]
【发布时间】:2018-02-28 06:49:02
【问题描述】:

我是 android 和 java 的新手,我需要一个问题的解决方案,我希望在 android 的工具栏中有一个 gif,它总是在屏幕出现时运行,我可以使用 koral's library 添加 gif 但我可以不知道如何在工具栏中添加这个 gif 我在 iOS 中做了这个并且能够在标签栏中添加 gif,我也需要在 android 中相同的 gif, 这是我真正想要的,任何帮助都会得到帮助

【问题讨论】:

    标签: android android-toolbar animated-gif


    【解决方案1】:

    像这样创建自定义工具栏布局。并将您的 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>
    

    【讨论】:

      【解决方案2】:

      使用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>
      

      【讨论】:

        【解决方案3】:

        您可以通过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);
        

        预览:

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2016-09-05
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多