2
我有一個ListView在每行中有2個TextView和一個CheckBox。在列表視圖上動畫背景
我有一個可繪製(線),我想一旦用戶選中該複選框的繪製將規模作爲在選中的複選框行的背景動畫,我能夠在我的getView()方法在我的自定義適配器上,將drawable作爲背景進行動畫處理,但它也可以縮放2 TextView和CheckBox,並且我希望只有可繪製的背景將作爲動畫縮放,我該怎麼做?
這裏是我的getView()的自定義適配器上方法:
public View getView(final int position, View convertView, final ViewGroup parent) {
final ViewHolder holder;
LayoutInflater inflater = LayoutInflater.from(context);
convertView = inflater.inflate(R.layout.listview_item_row, parent, false);
// cache view fields into the holder
holder = new ViewHolder();
holder.itemTitle = (TextView) convertView.findViewById(R.id.itemTitle);
holder.itemQuantity = (TextView) convertView.findViewById(R.id.itemQuantity);
holder.itemCheck = (CheckBox) convertView.findViewById(R.id.itemCheck);
convertView.setTag(holder);
final Cursor cursor = getCursor();
final View rowView = convertView;
cursor.moveToPosition(position);
holder.itemTitle.setText(cursor.getString((cursor.getColumnIndex(MySQLiteHelper.KEY_NAME))));
holder.itemQuantity.setText(cursor.getString((cursor.getColumnIndex(MySQLiteHelper.KEY_QUANTITY))));
holder.itemCheck.setChecked(cursor.getInt(cursor.getColumnIndex(MySQLiteHelper.KEY_CHECKED)) == 1);
holder.itemCheck.setOnCheckedChangeListener(new OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
cursor.moveToPosition(position);
itemsDataSource.updateItemCheckBox(1, cursor.getLong(cursor.getColumnIndex(MySQLiteHelper.KEY_ID)));
itemsDataSource.updateRoute(cursor.getString(cursor.getColumnIndex(MySQLiteHelper.KEY_NAME)), true);
Animation drawLine = AnimationUtils.loadAnimation(context, R.anim.item_done);
rowView.setBackgroundResource(R.drawable.line);
rowView.startAnimation(drawLine);
ShowListActivity.PRIORITY++;
}
else {
cursor.moveToPosition(position);
itemsDataSource.updateItemCheckBox(0, cursor.getLong(cursor.getColumnIndex(MySQLiteHelper.KEY_ID)));
itemsDataSource.updateRoute(cursor.getString(cursor.getColumnIndex(MySQLiteHelper.KEY_NAME)), false);
rowView.setBackgroundResource(0);
ShowListActivity.PRIORITY--;
}
}
});
if (holder.itemCheck.isChecked()) rowView.setBackgroundResource(R.drawable.line);
else rowView.setBackgroundResource(0);
return rowView;
}
private static class ViewHolder {
TextView itemTitle;
TextView itemQuantity;
CheckBox itemCheck;
}
代碼可以給出更好的想法。 –
請分享您的代碼,而不僅僅是一個理論 – swiftBoy
http://www.java-samples.com/showtutorial.php?tutorialid=1515閱讀本教程與列表中的縮放動畫可能對您有幫助 – DynamicMind