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;
}
}
Related
I have a cascate menu with inner elements. You can navigate on 2nd level and you should be able to return back to main one. The problem is that, notwithstanding the button animation hide the back button, it remains active on the background.
View.Gone is not working. Note: i use linear layouts.
/** CLICK SUL PULSANTE INDIETRO DA DASHBOARD */
dash_back.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
//Toast.makeText(getApplicationContext(), "back", Toast.LENGTH_LONG).show();
dd.setVisibility(View.GONE);
exitRight(dd);
new android.os.Handler().postDelayed(
new Runnable() {
public void run() {
ll.setVisibility(View.VISIBLE);
navigateRight(ll);
section = "main";
Toast.makeText(getApplicationContext(), "back", Toast.LENGTH_LONG).show();
dd.setVisibility(View.GONE);
}
},
200);
}
});
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);
}
});
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 have a class where I include another layout on a button click. This included layout has some buttons and a code which executes on clicking these buttons. I have used a counter which indicates the number of times the button is clicked. First time clicking on the button includes the layout and the second time clicking removes the views and so on. Here's the code
public class Home extends Fragment implements OnClickListener {
int c = 0;
Button bmain, bnew, bolder;
RelativeLayout r1;
View rootView;
Animation slidedown, slideup;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
rootView = inflater.inflate(R.layout.home, container, false);
bmain = (Button) rootView.findViewById(R.id.btn2);
bmain.setOnClickListener(this);
return rootView;
}
#Override
public void onClick(View arg0) {
ViewGroup con = null;
LayoutInflater layoutInflater = (LayoutInflater)getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
FrameLayout flContainer = (FrameLayout)rootView.findViewById(R.id.flContainer);
//Loading animation
slidedown = AnimationUtils.loadAnimation(getActivity(), R.anim.slide_down);
slideup = AnimationUtils.loadAnimation(getActivity(), R.anim.slide_up);
//The counter indicates the number of clicks.
//Needs to be replaced for a better solution.
//If it's even add view
if(c%2==0)
{
//Adding layout here
flContainer.addView(layoutInflater.inflate(R.layout.test1,con,false ));
//Starting Animation
flContainer.startAnimation(slidedown);
//After adding layout we can find the Id of the included layout and proceed from there
bnew = (Button) rootView.findViewById(R.id.btntest);
bnew.setOnClickListener(new OnClickListener()
{
#Override
public void onClick(View arg0) {
Toast.makeText(getActivity(), "You Clicked New", Toast.LENGTH_LONG).show();
}
});
bolder = (Button) rootView.findViewById(R.id.btntest1);
bolder.setOnClickListener(new OnClickListener()
{
#Override
public void onClick(View arg0) {
Intent form = new Intent(getActivity(),FeedbackForm.class);
startActivity(form);
}
});
c++;
} //If ends here
//If it's odd remove view
else
{
flContainer.removeAllViews();
flContainer.startAnimation(slideup);
//flContainer.removeView(flContainer);
//flContainer.removeView(layoutInflater.inflate(R.layout.test1, con, false));
c++;
}
}
}
The code at the end
flContainer.removeAllViews();
flContainer.startAnimation(slideup);
removes the view but fails to process the animation. I have tried using removeView but in that case the buttonclicks in the if statement fail to execute the second time. What am I missing here? How can I achieve it?
The answer is pretty simple. You have to remove the view after the animation is finished. This can be achieved pretty simple, first you have to set an animation listener for your animation and in the onAnimationEnd callback - which is called when the animation is finished - you remove the views.
EDIT:
Replace this:
flContainer.removeAllViews();
flContainer.startAnimation(slideup);
With this:
slideup.setAnimationListener(new Animation.AnimationListener() {
#Override
public void onAnimationStart(Animation animation) {
}
#Override
public void onAnimationEnd(Animation animation) {
flContainer.removeAllViews();
}
#Override
public void onAnimationRepeat(Animation animation) {
}
});
flContainer.startAnimation(slideup);
If there are any further problems let me know.
I have a ScrollView that contains a LinearLayout, in the LinearLayout I have a view that I expand or collapse depending on a button being pushed. This piece works just fine.
What I would like to do is re-position the ScrollView so that when the view is expanded it automatically re-positions the scroll view so that the expanded view is visible. I would like to the view to reposition it self automatically so the user does not have to scroll.
Currently when the view is expanded everything get's pushed down and you have to scroll up to view the newly expanded content. I tried repositioning after the animation has ended but that section of code never fires. Below is my code.
public void animateExpandCollapse(View v) {
View captionLayout = null;
View parentLayout = null;
if(v.getId() == R.id.squareCal) {
captionLayout = (LinearLayout) findViewById(R.id.layout3);
parentLayout = (LinearLayout) findViewById(R.id.squareLayout);
} else if(v.getId() == R.id.circleCal) {
captionLayout = (LinearLayout) findViewById(R.id.layout2);
parentLayout = (LinearLayout) findViewById(R.id.circleLayout01);
}
if (!more) {
dda = new DropDownAnim(captionLayout, 350, false);
more=true;
} else {
dda = new DropDownAnim(captionLayout, 350, true);
more=false;
}
dda.setDuration(350);
parentLayout.startAnimation(dda);
// Here, I want to position ScrollView to the bottom
// After the animation has finished but this never fires.
if(dda.hasEnded() ) {
ScrollView sv = (ScrollView)findViewById(R.id.calScroller);
sv.scrollTo(0, sv.getBottom());
}
return;
}
After searching online I found the following solution. I hope this helps someone.
dda.setAnimationListener(new AnimationListener() {
#Override
public void onAnimationStart(Animation animation) {
}
#Override
public void onAnimationRepeat(Animation animation) {
}
#Override
public void onAnimationEnd(Animation animation) {
ScrollView sv = (ScrollView)findViewById(R.id.calScroller);
sv.scrollTo(0, sv.getBottom());
}
});