点賛アニメーションはlistviewで実現
4696 ワード
ネット上では多くの点賛効果が単独で実現されていますが、問題が来て、私たちは一般的にリストに1つのものを展示しています.私たちは点賛buttonは一般的にリストの中にあるので、Adapterの中のgetViewに機能を書く必要があります.
くだらないことは言わないで、直接コード:
Listviewのレイアウトファイルでは、「いいね」のbuttonの下に+1が隠されています.
以下はAdapterファイルです.残りの省略は主にgetViewクリップです.
主な注意OnClicListenerイベント
最後にアニメーションのnnファイルを添付します:
くだらないことは言わないで、直接コード:
Listviewのレイアウトファイルでは、「いいね」のbuttonの下に+1が隠されています.
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_toLeftOf="@+id/relativeLayout1" >
<Button
android:id="@+id/bt_one"
android:layout_width="40dip"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:gravity="center"
android:text=" "
android:textColor="#000000"
android:textSize="18dp"
/>
<TextView
android:id="@+id/tv_one"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="+1"
android:layout_centerInParent="true"
android:visibility="gone"
android:gravity="center"
android:textSize="18dp"
android:textColor="#000000"
/>
</RelativeLayout>
以下はAdapterファイルです.残りの省略は主にgetViewクリップです.
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
// animation=AnimationUtils.loadAnimation(context,R.anim.nn);
final ObjectEntity objentity=hotobjList.get(position);
ViewHolder holder = null;
if(convertView==null){
holder = new ViewHolder();
convertView = LayoutInflater.from(context).inflate(R.layout.listitem_hotobj, null);
holder.starn= (TextView) convertView.findViewById(R.id.starname);
holder.objt = (TextView) convertView.findViewById(R.id.objecttype);
holder.objpopty=(TextView) convertView.findViewById(R.id.objectpopty);
holder.objpic=(ImageView)convertView.findViewById(R.id.objpic);
holder.zanbt=(Button)convertView.findViewById(R.id.bt_one);
holder.plus1=(TextView)convertView.findViewById(R.id.tv_one);
convertView.setTag(holder);
}else
{
holder = (ViewHolder)convertView.getTag();
}
holder.starn.setText(objentity.getStar_Name());
holder.objt.setText(objentity.getObject_Type());
int i=objentity.getObject_Popty();
holder.objpopty.setText(Integer.toString(i));
holder.objpic.setImageDrawable(objentity.getObject_pic());
holder.zanbt.setTag(position);
// Button Button ListView Button
//holder.zanbt.setOnClickListener( myListener);
final TextView tv=holder.plus1;
final TextView tv2=holder.objpopty;
holder.zanbt.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
/* holder.plus1.setVisibility(View.VISIBLE);
ObjectAnimator oa=ObjectAnimator.ofFloat(holder.plus1, "translate", 1.0f, 2f);
oa.setDuration(3000);
oa.start();
holder.plus1.setVisibility(View.GONE);*/
tv.setVisibility(View.VISIBLE);
//tv2.setText("100");
System.out.println("__animation1");
tv.startAnimation(animation);
System.out.println("__animation2");
new Handler().postDelayed(new Runnable(){
public void run() {
//holder.plus1.clearAnimation();
tv.setVisibility(View.GONE);
tv2.setText("100");
objentity.setObject_Popty(100);
}
}, 1000);
}
});
return convertView;
}
}
主な注意OnClicListenerイベント
最後にアニメーションのnnファイルを添付します:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<!--
<scale
android:fromXScale="1.0"
android:toXScale="1.0"
android:fromYScale="0"
android:toYScale="1.0"
android:pivotX="50%"
android:pivotY="0%"
android:duration="1000" />
-->
<translate
android:fromXDelta="0"
android:toXDelta="0"
android:fromYDelta="0"
android:toYDelta="-50"
android:duration="1000"/>
<alpha
android:fromAlpha="1.0"
android:toAlpha="0.3"
android:duration="1000"/>
</set>