私はトグルボタンの束を持っているListViewを持っています。これらのトグルボタンでは、トグルで色を変更するためのアニメーションがありますが、データをトグルする必要があるかどうかによって色を変更するように設定しています。 (togglebuttonが正しい色であるようにスクロールアップ/スクロールするとき)、問題はトグルボタンをタップするとアニメーションが開始されますが、getViewが再び呼び出され、アニメーションが色の間で移行を開始した直後です数ミリ秒間完全にトグル状態になるまで色が点滅し、その後アニメーション値に戻ります。トグルでアニメーションがちらつくことなく、ListViewでToggleButtonをアニメ化できますか?
どのように機能するのか、ユーザーが切り替えたときにフリッカーを削除するにはどうすればよいですか?私はビデオを持っていたが、ちらつきがスクリーンレコーダーがそれをキャプチャするには速すぎる。ここで
は、このすべての責任ListViewのための私のアダプタです:
public View getView(int position, View convertView, ViewGroup parent) {
View ListItem = convertView;
Holder holder;
final dieties diety = data[position];
// Log.d(TAG, position + " - pos. ");
if (ListItem == null) {
LayoutInflater inflater = ((Activity) context).getLayoutInflater();
ListItem = inflater.inflate(layoutResourceId, parent, false);
holder = new Holder();
holder.banner = (ImageView) ListItem.findViewById(R.id.dietyBanner);
holder.website = (Button) ListItem.findViewById(R.id.dietyWebsite);
holder.active = (ToggleButton) ListItem.findViewById(R.id.isActiveButtonToggle);
holder.highlight = (ImageView) ListItem.findViewById(R.id.highlight);
holder.title = (TextView) ListItem.findViewById(R.id.titleText);
// holder.description = (TextView) ListItem.findViewById(R.id.dietyDesc);
// holder.background = (RelativeLayout) ListItem.findViewById(R.id.listItemBG);
// holder.highlight2 = (ImageView) ListItem.findViewById(R.id.highlight2);
View.OnClickListener holderListener = new View.OnClickListener() {
public void onClick(View v) {
WebView webView = (WebView) ((Activity) context).findViewById(R.id.webView);
webView.setVisibility(View.VISIBLE);
webView.loadUrl(diety.url);
}
};
holder.website.setOnClickListener(holderListener);
ListItem.setTag(holder);
} else {
holder = (Holder) ListItem.getTag();
}
CompoundButton.OnCheckedChangeListener ToggleButtonListener = new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
// int position = (int) buttonView.getParent().getT();
// dieties diety = data[position];
diety.active = isChecked;
SharedPreferences sharedPref = ((Activity) context).getPreferences(Context.MODE_PRIVATE);
SharedPreferences.Editor prefeditor = sharedPref.edit();
prefeditor.putBoolean(Integer.toString(diety.id), isChecked);
prefeditor.apply();
Log.d(TAG, diety.id + " changed to " + diety.active);
notifyDataSetChanged();
TextView dietyActiveCount = (TextView) ((Activity) context).findViewById(R.id.dietySelectedCounter);
final CompoundButton Button = buttonView;
final RelativeLayout r = (RelativeLayout) ((ViewGroup) Button.getParent()).getParent();
int startColor = isChecked ? Color.parseColor("#ce5a5a") : Color.parseColor("#2e7d32");
int endColor = isChecked ? Color.parseColor("#2e7d32") : Color.parseColor("#ce5a5a");
ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), startColor, endColor);
colorAnimation.setDuration(100);
colorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
ImageView sideThing1 = (ImageView) r.findViewById(R.id.highlight);
// ImageView sideThing2 = (ImageView) r.findViewById(R.id.highlight2);
sideThing1.setBackgroundColor((int) animation.getAnimatedValue());
// sideThing2.setBackgroundColor((int) animation.getAnimatedValue());
Button.setBackgroundColor((int) animation.getAnimatedValue());
}
});
colorAnimation.start();
calcCounter();
if (currentlyActive == 1){
dietyActiveCount.setText("1 diety Selected");
} else {
dietyActiveCount.setText(currentlyActive + " dieties Selected");
}
}
};
holder.active.setOnCheckedChangeListener(ToggleButtonListener);
Log.d(TAG, diety.id + "");
SharedPreferences sharedPref = ((Activity) context).getPreferences(Context.MODE_PRIVATE);
diety.active = sharedPref.getBoolean(Integer.toString(diety.id), false);
holder.active.setOnCheckedChangeListener (null);
holder.active.setChecked (diety.active);
if (diety.active) {
holder.active.setBackgroundColor(Color.parseColor("#2e7d32"));
holder.highlight.setBackgroundColor(Color.parseColor("#2e7d32"));
// holder.highlight2.setBackgroundColor(Color.parseColor("#2e7d32"));
} else {
holder.active.setBackgroundColor(Color.parseColor("#ce5a5a"));
holder.highlight.setBackgroundColor(Color.parseColor("#ce5a5a"));
// holder.highlight2.setBackgroundColor(Color.parseColor("#ce5a5a"));
}
holder.active.setOnCheckedChangeListener (ToggleButtonListener);
holder.banner.setImageResource(diety.banner);
// holder.description.setText(diety.description);
holder.banner.setBackgroundColor(Color.parseColor("#616161"));
// holder.description.setText(diety.url);
holder.title.setText(diety.title);
return ListItem;
}
static class Holder {
TextView title;
ImageView banner;
Button website;
ToggleButton active;
ImageView highlight;
}