Android 如何在布局的gridview中闪烁(或设置动画)特定子项
下面是我用来显示使用gridview创建的网格的代码,它有图像,图像下方显示文本。我想让一些文本闪烁,例如“image text3”和“image text5”,这样用户就可以知道文本闪烁和不闪烁之间的区别。谁能帮我一下吗Android 如何在布局的gridview中闪烁(或设置动画)特定子项,android,android-animation,Android,Android Animation,下面是我用来显示使用gridview创建的网格的代码,它有图像,图像下方显示文本。我想让一些文本闪烁,例如“image text3”和“image text5”,这样用户就可以知道文本闪烁和不闪烁之间的区别。谁能帮我一下吗 GridView mGridMain1 = (GridView)findViewById(R.id.gvMain1); Resources res = getResources(); List<AppInfo> listAppInfo = new ArrayLis
GridView mGridMain1 = (GridView)findViewById(R.id.gvMain1);
Resources res = getResources();
List<AppInfo> listAppInfo = new ArrayList<AppInfo>();
listAppInfo.add(new AppInfo(BitmapFactory.decodeResource(res, R.drawable.image1), "image text1"));
listAppInfo.add(new AppInfo(BitmapFactory.decodeResource(res, R.drawable.image2), "image text2"));
listAppInfo.add(new AppInfo(BitmapFactory.decodeResource(res, R.drawable.image3), "image text3"));
listAppInfo.add(new AppInfo(BitmapFactory.decodeResource(res, R.drawable.image4), "image text4"));
listAppInfo.add(new AppInfo(BitmapFactory.decodeResource(res, R.drawable.image5), "image text5"));
listAppInfo.add(new AppInfo(BitmapFactory.decodeResource(res, R.drawable.image6), "image text6"));
listAppInfo.add(new AppInfo(BitmapFactory.decodeResource(res, R.drawable.image7), "image text7"));
listAppInfo.add(new AppInfo(BitmapFactory.decodeResource(res, R.drawable.image8), "image text8"));
mGridMain1.setAdapter(new AppInfoAdapter(this, listAppInfo));
mGridMain1.setOnItemClickListener(mItemClickListener);
GridView mGridMain1=(GridView)findViewById(R.id.gvMain1);
Resources res=getResources();
List listAppInfo=new ArrayList();
添加(新的AppInfo(BitmapFactory.decodeResource(res,R.drawable.image1),“图像文本1”);
添加(新的AppInfo(BitmapFactory.decodeResource(res,R.drawable.image2),“图像文本2”);
添加(新的AppInfo(BitmapFactory.decodeResource(res,R.drawable.image3),“图像文本3”);
添加(新的AppInfo(BitmapFactory.decodeResource(res,R.drawable.image4),“图像文本4”);
添加(新的AppInfo(BitmapFactory.decodeResource(res,R.drawable.image5),“图像文本5”);
添加(新的AppInfo(BitmapFactory.decodeResource(res,R.drawable.image6),“图像文本6”);
添加(新的AppInfo(BitmapFactory.decodeResource(res,R.drawable.image7),“图像文本7”);
添加(新的AppInfo(BitmapFactory.decodeResource(res,R.drawable.image8),“图像文本8”);
mGridMain1.setAdapter(新的AppInfoAdapter(this,listAppInfo));
mGridMain1.setOnItemClickListener(mItemClickListener);
当然,Android支持即时闪烁标签!只需膨胀一个使用它的布局,你就完成了。查看此提交:。我认为您只能通过创建一个自定义适配器类来告诉要对哪个项设置动画(闪烁)才能在GridView
的子项(ChildView
)上实现动画
使用BaseAdapter
class创建自定义适配器
public class GridViewAdapterCustom extends BaseAdapter {
Context mContext;
List<AppInfo> listAppInfo;
public ListViewAdapterCustom(Context con,List<AppInfo> list){
mContext=con;
listAppInfo=list;
}
public int getCount() {
return list.size();
}
@Override
public Object getItem(int i) {
return null;
}
@Override
public long getItemId(int i) {
return i;
}
@Override
public View getView(int i, View view, ViewGroup viewGroup) {
LayoutInflater inflater = (LayoutInflater)con.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View row; row = inflater.inflate(R.layout.listitemview, viewGroup, false);}
//Add this code to whichever textview you want to animate
TextView blinkable_text = (TextView)row.findViewById(R.id.textView);
Animation myFadeInAnimation;
Animation myFadeInAnimation = AnimationUtils.loadAnimation(null, R.anim.fade_in);
blinkable_text.startAnimation(myFadeInAnimation);
return row;
}
}
创建您自己的
listitemview.xml
文件以初始化和设置文本字段您可以将动画添加到AppInfoAdapter
中网格中的特定位置,当用户开始滚动GridView
时,您的GridView
项目应该如何运行?问题很不清楚。。。图像应该在什么条件下闪烁?您可以根据我这里的示例示例示例应用程序编写代码如果您使用适配器显示网格视图,您可以在适配器中添加条件以显示突出显示的特定区域您可以根据您的要求在适配器中设置背景首先清除您的要求Blundell:您可以帮我制作动画吗?未记录,不在2.2上工作且无法控制闪烁(fx:如何停止闪烁?)
<?xml version="1.0" encoding="UTF-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha android:fromAlpha="0.0"
android:toAlpha="1.0"
android:interpolator="@android:anim/accelerate_interpolator"
android:duration="50" android:repeatCount="infinite"/>
</set>