【问题标题】:Gif Image in SnackbarSnackbar 中的 Gif 图像
【发布时间】:2019-02-05 03:36:13
【问题描述】:

我正在做我学校的音乐播放器项目。我能够从外部驱动器中获取歌曲列表,并能够在 Fragment 下的 listView 中显示相同的歌曲列表。当我点击歌曲时,它会播放并打开snackbar

我希望这个Snackbar 显示带有动画的“gif 图像”。我尝试了几个在线代码,但无法找到任何解决方案

下面是我的代码:

Snackbar snackbar = Snackbar.make(relativeLayout, nameOfSong , Snackbar.LENGTH_INDEFINITE);
View snackbarLayout = snackbar.getView();
TextView textView = (TextView)snackbarLayout.findViewById(android.support.design.R.id.snackbar_text);
textView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.musicbars, 0, 0, 0); 
textView.setCompoundDrawablePadding(getResources().getDimensionPixelOffset(R.dimen.my_value));
snackbar.show();

我想添加音乐条的 Gif,它应该会一直保持动画效果,直到歌曲结束。

谢谢

【问题讨论】:

标签: android animated-gif android-snackbar


【解决方案1】:

Android 中的自定义 SnackBar

试试这个创建自定义 Snackbar 布局并在 ImageView 中加载 gif 图像,我希望这对您有所帮助,并访问在 ImageViewLoad gif in ImageView 中加载 gif 的链接

Snackbar snackbar = Snackbar.make(parentLayout, "", Snackbar.LENGTH_LONG);
Snackbar.SnackbarLayout layout = (Snackbar.SnackbarLayout) 
snackbar.getView();
TextView textView = (TextView) 
layout.findViewById(android.support.design.R.id.snackbarText);
textView.setVisibility(View.INVISIBLE);

View snackView = mInflater.inflate(R.layout.snckBar, null);
ImageView imageView = (ImageView) snackView.findViewById(R.id.image);
imageView.setImageBitmap(image);
TextView textViewTop = (TextView) snackView.findViewById(R.id.text);
textViewTop.setText(text);
textViewTop.setTextColor(Color.WHITE);
layout.setPadding(0,0,0,0);
layout.addView(snackView,0);
snackbar.show();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-11-04
    • 2018-01-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-21
    • 1970-01-01
    相关资源
    最近更新 更多