Animation of slides and slides for the layout

I have LinearLayout, I am dynamically adding TextView, ImageView to that LinearLayout , now I have added OnClickListener to these TextViews and ImageViews.

I have an arraylist that has 10 elements in it using a for loop. I get each value and display, since this quiz application has the following and previous buttons, when I click on it, I show the elements one by one from the arraylist. Now I need slide In and slide Out animation to apply to this Linear Layout.

I saw this:

Link 1

Link 2

as well as i tried this

 slideIn = new TranslateAnimation( TranslateAnimation.RELATIVE_TO_PARENT, 1.0f, TranslateAnimation.RELATIVE_TO_PARENT, 0.0f, TranslateAnimation.RELATIVE_TO_PARENT, 0.0f, TranslateAnimation.RELATIVE_TO_PARENT, 0.0f); slideIn.setDuration(500); slideOut = new TranslateAnimation( TranslateAnimation.RELATIVE_TO_PARENT, 0.0f, TranslateAnimation.RELATIVE_TO_PARENT, -1.0f, TranslateAnimation.RELATIVE_TO_PARENT, 0.0f, TranslateAnimation.RELATIVE_TO_PARENT, 0.0f); slideOut.setDuration(500); 

But don’t work, please help with this.

EDIT:

Problem: I applied this to the linear layout, but what happens is that when I click on the next button, the current question will slide left and a blank screen, then it will slide and display the next question, but I want the current question to fail, for the following question should follow.

+6
source share
2 answers

If your layouts have the same content, create two layouts inside the view flipper. Download the first data view and show it. When the user clicks the next or previous one, load the next data view and save the flag to show that the 2nd view is now showing and showing it with animation.

Now now load the appropriate views with data based on the flag values ​​and showext () is called.

 protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mainFlipper = (ViewFlipper) findViewById(R.id.flipper); firstLayout = (LinearLayout) findViewById(R.id.layout1); secondLayout = (LinearLayout) findViewById(R.id.layout2); findViewById(R.id.btnPrevious).setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { showPrevious(); } }); findViewById(R.id.btnNext).setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { showNext(); } }); } private void showNext() { mainFlipper.setInAnimation(AnimationUtils.loadAnimation(this, R.anim.slide_in_left)); mainFlipper.setOutAnimation(AnimationUtils.loadAnimation(this, R.anim.slide_out_right)); flip(); } private void showPrevious() { mainFlipper.setInAnimation(AnimationUtils.loadAnimation(this, R.anim.slide_in_right)); mainFlipper.setOutAnimation(AnimationUtils.loadAnimation(this, R.anim.slide_out_left)); flip(); } private void flip() { if(isFirstVisible) { isFirstVisible = false; secondLayout.removeAllViews(); secondLayout.addView(getTextView("Second")); } else { isFirstVisible = true; firstLayout.removeAllViews(); firstLayout.addView(getTextView("First")); } mainFlipper.showNext(); } private TextView getTextView(String txt) { TextView txtView = new TextView(this); txtView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); txtView.setText(txt); return txtView; } 
+3
source

Use this xml in res / anim /

leftright.xml
This is for animation from left to right:

  <set xmlns:android="http://schemas.android.com/apk/res/android" android:shareInterpolator="false"> <translate android:fromXDelta="-100%" android:toXDelta="0%" android:fromYDelta="0%" android:toYDelta="0%" android:duration="700"/> </set> 

use this in your java code

 Handler handler = new Handler(); Runnable runnable = new Runnable(){ { public void run() { item[i].setInAnimation(AnimationUtils.loadAnimation(this,R.anim.leftright.xml)); i=i+1; handler.postDelayed(this,5000); } };handler.postDelayed(runnable,5000); 
+4
source

All Articles