Android Animation not work when i call visibility - android

The animation does not work after I set visibility to Invisible, I tried clear animation but not work. I have a button when I click the button it opens a linear layout with animation when I press back button I set the linear layout visibility to invisible again I click the button linear layout appear but no animation please help me.
l1 = (LinearLayout) findViewById(R.id.lnrlgn);
l2 = (LinearLayout) findViewById(R.id.lnrlgn1);
l2.setVisibility(View.INVISIBLE);
Animation uptodown = AnimationUtils.loadAnimation(this,R.anim.uptodown);
viewcrrd.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
l2.setAnimation(downtoup);
l2.clearanimation(); // is it right ?
l2.setVisibility(View.VISIBLE);
}
});
public void onBackPressed() {
// super.onBackPressed();
if (back_pressed + TIME_DELAY > System.currentTimeMillis()) {
// super.onBackPressed();
Exitdlg alert = new Exitdlg();
alert.showDialog(LoginActivity.this, "Are You Sure ");
l2.clearAnimation();
} else {
l2.clearAnimation();
l2.setVisibility(View.INVISIBLE);
}
back_pressed = System.currentTimeMillis();
}

Use startAnimation instead of setAnimation
viewcrrd.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
l2.setVisibility(View.VISIBLE);
l2.clearanimation();
l2.startAnimation(downtoup);
}
});

Related

Disable click after clicking the textview

I have a TextView and I put a OnClickListener on this TextView. I use this action to load custom view onto a LinearLayout.
But when I click on this TextView twice, custom view is repeating on the LinearLayout. I clear all custom views on this LinearLayout before I load new custom views on to this LinearLaout.
This is my OnClickListener on TextView,
TextView rejectedTitleTextView = (TextView) findViewById(R.id.roster_menu_rejected_title);
rejectedTitleTextView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
rejectedTitleTextView.setBackgroundColor(getResources().getColor(R.color.acceptedPurpleColour));
newTitleTextView.setBackgroundColor(getResources().getColor(R.color.defaultBlack));
acceptedTitleTextView.setBackgroundColor(getResources().getColor(R.color.defaultBlack));
locationLinearLayout.removeAllViews();
rosterBottomLayout.setVisibility(View.GONE);
Log.d("CHECK_ACTION"," REJECTED_TEXT_VIEW ");
InternetConnectivity internetConnectivity = new InternetConnectivity();
final boolean isConnectedToInternet = internetConnectivity.isConnectedToInternet(context);
if(isConnectedToInternet==true) {
try {
Thread.sleep(1300);
} catch (Exception e) {
e.printStackTrace();
}
getDataFromServer("REJECTED");
}else{
Snackbar.make(mainView, "No Internet Connection", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
}
});
getDataFromServer("REJECTED");
is the method which I used to load custom view onto this LinearLayout.
How can I prevent this issue ?
Have any ideas ?
Inside onclickListener put
rejectedTitleTextView.setClickable(false);
and once finish your functionality make it as true because u need to click for next time .
rejectedTitleTextView.setClickable(true);
Inside setOnclickListener try below code:-
textView.setClickable(false);
Try this
rejectedTitleTextView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
mSpinner.setEnabled(false);
mSpinner.postDelayed(new Runnable() { #Override public
void run() {
mSpinner.setEnabled(true); }
}
// do your stuff here
});
You can maintain boolean value like this
boolean isClick=false;
rejectedTitleTextView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if(!isClick)
{
//do your Stuff on onCLick
isClick=true;
}else
{
//leave it blank if you do not want to do anything second time
}
}
});

How can I make previous item's button visible when click on current item's button in recyclerview?

What I want is when I click the "x" button of the second item, it will remove the second item and then make the "+" of the first item visible. Here is what I try but not work, the "+" button is not showed.
holder.ivDelete.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
View view = recyclerView.getChildAt(position - 1);
holder.ivAdd = (ImageView) view.findViewById(R.id.img_add_items);
holder.ivAdd.setVisibility(View.VISIBLE);
list.remove(position);
notifyDataSetChanged();
}
});
Try this code,
holder.ivDelete.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
View view = recyclerView.getChildItemId(position - 1);
holder.ivAdd = (ImageView) view.findViewById(R.id.img_add_items);
holder.ivAdd.setVisibility(View.VISIBLE);
list.remove(position);
notifyDataSetChanged();
}
});
I hope that will help you for solving your problem.

setVisible not always in operation

I have LinearLayout and a Button, in layout I have a SeekBar and when click button I show or hide LinearLayout, I used View.GONE and View.Visible to hide and show.
It work in many devices but when I test it in Note Edge or cool pad It does not work.
What is happening here?
rlFont = (RelativeLayout) rootView.findViewById(R.id.rlFont);
ivFont.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (ivFont.getDrawable().getConstantState().equals(getActivity().getResources().getDrawable(R.drawable.top_a001).getConstantState())) {
ivFont.setImageResource(R.drawable.top_a002);
rlFont.setVisibility(View.VISIBLE);
rlFont.requestLayout();
} else {
ivFont.setImageResource(R.drawable.top_a001);
rlFont.setVisibility(View.GONE);
rlFont.requestLayout();
}
}
});
This can solve your problem, with this is possible to toggle your button.
boolean isClicked = false;
rlFont = (RelativeLayout) rootView.findViewById(R.id.rlFont);
ivFont.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (!isClicked) {
ivFont.setImageResource(R.drawable.top_a002);
rlFont.setVisibility(View.VISIBLE);
rlFont.requestLayout();
isClicked = true;
} else {
ivFont.setImageResource(R.drawable.top_a001);
rlFont.setVisibility(View.GONE);
rlFont.requestLayout();
isClicked = false;
}
}
});

Slide down/Slide Up animation on changing visibility of a Relative Layout

I have a RelativeLayout in my View whose visibility is set as GONE. I need to provide a slide down translation and also set the visibility as VISIBLE for the RelativeLayout over the ListView on button press and Slide up animation on button press by.
replyMessage.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
//slideToBottom(replyLayout);
Toast.makeText(getActivity(), "Reply pressed",
Toast.LENGTH_SHORT).show();
TranslateAnimation animate = new TranslateAnimation(0,0,0,replyLayout.getHeight());
animate.setDuration(1000);
animate.setFillAfter(true);
replyLayout.startAnimation(animate);
replyLayout.setVisibility(View.VISIBLE);
if(replyFlag){
replyMessage.setImageResource(R.drawable.reply_active);
replyFlag = true;
}else{
replyMessage.setImageResource(R.drawable.reply_img);
replyFlag = false;
}
}

give animation effect when click button on galleryview android

When I use Gallery widget, how do I get animate when I click a button to move from one picture to another??
Here is my screenshot of my gallery
When I swipe I got an animation like bounce effect, but when I click the prev and the next button, the picture just change without any animation.
Is there any way to attach some animation like slide efefct or something???
and here is my code
bnext.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
if (selectedImagePosition < Imgid.length - 1) {
++selectedImagePosition;
}
gallery.setSelection(selectedImagePosition, false);
gallery.startAnimation(grow);
}
});
bprev.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
if (selectedImagePosition > 0) {
--selectedImagePosition;
}
gallery.setSelection(selectedImagePosition, false);
}
});
Thanks

Categories

Resources