So when I click a list item in my ListView it gets animated. The problem is that when it's animating I can still click it and this is undesirable. I'm using nineOldAndroids and to disable the ListItem I do:
set.addListener(new Animator.AnimatorListener() {
#Override
public void onAnimationStart(Animator animator) {
v.setClickable(false);
v.setEnabled(false);
}
#Override
public void onAnimationEnd(Animator animator) {
v.setClickable(true);
v.setEnabled(true);
}
#Override
public void onAnimationCancel(Animator animator) {
}
#Override
public void onAnimationRepeat(Animator animator) {
}
});
setClickable behaves strangely: it does let me click the list item for a brief time after the animation starts and after the animation ends it won't let me click it anymore (even though I set it to true). And setEnabled doesn't work at all.
How can I disable a list Item while an animation is running?
make the adapter isEnabled(int position) method return false while the animation on that item is going on.
add this to your adapter
Set<Integer> disabledItems;
private void setRowEnabled(int position,boolean enabled){
if(enabled){
disabledItems.remove(position);
}else{
disabledItems.add(position);
}
}
#Override
public boolean isEnabled(int position) {
return !disabledItems.contains(position);
}
And call the setRowEnabled from the onAnimationStart onAnimationEnd of your Animation
Related
I have a recyclerview which has animation added for each item in onBindViewHolder() which results in multiple calls for single item in recycler view.
My requirement is to zoom in image on selection of an item in recycler-view. I have started an animation in onBindViewHolder() for each item which has resulted in continuous calls of onBindViewHolder() for same item.
#Override
public void onBindViewHolder(#NonNull BaseViewHolder viewHolder, int viewType) {
viewHolder.imageView.animate().scaleX(scaleX).scaleY(scaleY).setListener(new Animator.AnimatorListener() {
#Override
public void onAnimationStart(Animator animation) {
}
#Override
public void onAnimationEnd(Animator animation) {
viewHolder.imageView.animate().setListener(null);
}
#Override
public void onAnimationCancel(Animator animation) {
}
#Override
public void onAnimationRepeat(Animator animation) {
}
}).setDuration(THUMBNAIL_ZOOMING_DURATION).start();
}
Imageview should zoom in by 1.15f when an item gets selected with animation and should get zoom out if deselected.
onBindViewHolder is not a good place for animations. Try using onViewAttachedToWindow to start and onViewDetachedFromWindow to stop animations
I have a form with a clickeable cardview. Depending on some of the options, I hide the CardView setting its visibility to GONE.
Other form controls below the card come up to occupy the space the cardview was taking. However when clicking in the area the Cardview used to be, the onclick event is fired for the cardview.
I even put a check to verify the visibility before the click action, but the cardview repots VISIBLE (even though its not being shown). I use Butterknife for the onClick event:
#OnClick(R.id.logo_cardview)
public void onLogoClick(){
if (mLogoCardView.getVisibility() == VISIBLE) {
Snackbar.make(this, "Logo clicked", Snackbar.LENGTH_SHORT).show();
showSettingsDialog();
}
}
I hide the Cardview using an animation:
mAlphaAnimation = new AlphaAnimation(1.0f, 0.0f);
mAlphaAnimation.setDuration(200);
mAlphaAnimation.setFillAfter(true);
mHideListener = new Animation.AnimationListener() {
#Override
public void onAnimationStart(Animation animation) {
}
#Override
public void onAnimationEnd(Animation animation) {
mMatchInfo.setVisibility(View.GONE);
}
#Override
public void onAnimationRepeat(Animation animation) {
}
};
I am trying to have a view animated in my app and am using NineOldAndroid for animations.
The desired effect is to fade the view out and then set it's visibility to gone so that it doesn't get clicked while invisible. Here is How I do it.
ViewPropertyAnimator.animate(view).alpha(0).setListener(new Animator.AnimatorListener() {
#Override
public void onAnimationStart(Animator animation) {
}
#Override
public void onAnimationEnd(Animator animation) {
view.setVisibility(View.GONE);
}
#Override
public void onAnimationCancel(Animator animation) {
}
#Override
public void onAnimationRepeat(Animator animation) {
}
});
The problem here is that the listener above sticks with the view and when I try to fade it in again the listener gets called again resulting the view to be GONE upon appearing.
ViewPropertyAnimator.animate(enterGallery).alpha(1);
How can I clear the listener after the view visibility is set to GONE in the first piece of code?
I found the solution and it would be to pass null as listener when making the view VISIBLE.
ViewPropertyAnimator.animate(view).alpha(1).setListener(null);
I want to set Animation to images of in image view like in newsstand application and change image after particular interval of time.
Please help its very important for me.
for animating a view (image view included) i recommend this library
set the animation time and when it ends change the image, full code for the code snippet
rope = YoYo.with(Techniques.FadeIn).duration(1000).playOn(mTarget);// after start,just click mTarget view, rope is not init
mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Techniques technique = (Techniques)view.getTag();
rope = YoYo.with(technique)
.duration(1200)
.interpolate(new AccelerateDecelerateInterpolator())
.withListener(new Animator.AnimatorListener() {
#Override
public void onAnimationStart(Animator animation) {
}
#Override
public void onAnimationEnd(Animator animation) {
//change image here
}
#Override
public void onAnimationCancel(Animator animation) {
Toast.makeText(MyActivity.this, "canceled", Toast.LENGTH_SHORT).show();
}
#Override
public void onAnimationRepeat(Animator animation) {
}
})
.playOn(mTarget);
}
});
I am willing to create a news bar in android application and I used the animation to move TextView from left to right and fill it each round with a new text from array of strings. I faced a lot of problems and I used more than 5 ways but each one has a bad behaviour. the main problem is that when the animation ends it refreshes the textView and it appears like flashing which is not a user-friendly behaviour.
Here is a code snippet:
TextView my_text;
Animation slideRight;
Animation slideLeft;
String [] text = {"TwoOneOneOneOneOneOneOneOneOneTwo","OneTwoTwoTwoTwoTwoTwoTwoTwoTwoTwoOne",
"OneThreeThreeThreeThreeThreeThreeThreeOne","OneFourFourFourFourFourFourFourOne",
"OneFiveFiveFiveFiveFiveFiveFiveOne","OneSixSixSixSixSixSixSixOne",
"OneSevenSevenSevenSevenSevenSevenSeveOne","OneEightEightEightEightEightEightEightOne",
"OneNineNineNineNineNineNineNineOne"};
int arr_length;
int count = 0;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
arr_length = text.length;
slideRight = AnimationUtils.loadAnimation(this, android.R.anim.slide_out_right);
slideRight.setDuration(2000);
slideRight.setRepeatCount(Animation.INFINITE);
slideRight.setAnimationListener(slideRightListener);
slideLeft = AnimationUtils.loadAnimation(this, android.R.anim.slide_in_left);
slideLeft.setDuration(2000);
slideLeft.setAnimationListener(slideLeftListener);
my_text = (TextView) findViewById(R.id.textView1);
my_text.setVisibility(TextView.VISIBLE);
my_text.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(getApplicationContext(), my_text.getText(), Toast.LENGTH_SHORT).show();
}
});
slideLeft.setAnimationListener(slideLeftListener);
my_text.startAnimation(slideLeft);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
AnimationListener slideLeftListener = new AnimationListener() {
#Override
public void onAnimationStart(Animation animation) {
my_text.setVisibility(TextView.VISIBLE);
}
#Override
public void onAnimationRepeat(Animation animation) {
my_text.setVisibility(TextView.VISIBLE);
}
#Override
public void onAnimationEnd(Animation animation) {
my_text.setVisibility(TextView.VISIBLE);
my_text.startAnimation(slideRight);
}
};
AnimationListener slideRightListener = new AnimationListener() {
#Override
public void onAnimationStart(Animation animation) {
my_text.setVisibility(TextView.VISIBLE);
}
#Override
public void onAnimationRepeat(Animation animation) {
my_text.setVisibility(TextView.VISIBLE);
}
#Override
public void onAnimationEnd(Animation animation) {
my_text.setVisibility(TextView.VISIBLE);
if(count<arr_length)
{
my_text.setText(text[count]);
count+=1;
my_text.startAnimation(slideLeft);
}
else
{
count=0;
my_text.setText(text[count]);
my_text.startAnimation(slideLeft);
}
}
};
}
I think ViewFlipper is more suitable for you.
Try adding setFillAfter(true) as that might stop the "refresh" behavior at the end of the Animation.
As I commented on #Bill above I realized that the refresh issue related to Android version.
I have tested the same code above on devices with Android Ice-Cream-Sandwich and it didn't "refresh".
If there is any solution on non-ICS I will accept it.
I've got this link and I found it great to me and can be customized as my requirements.
It uses HorizonalSlideshow.