How to make buttons change with animation
-
i should to do like at the picture. Buttons have to change with animations. It must be like circle horizontal scroll view.When i press button "3" - "1" - moved to position "2", "2" moved with animation to position "3". Please give me some ideas, how can i perform it?
-
Answer:
Try this.. STEP 1: Create 4 Button's dummy_btn,btn_1,btn_2,btn_3 in xml like below <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_gravity="center" android:gravity="center" > <Button android:id="@+id/dummy_btn" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_margin="5dp" android:layout_weight="1" android:text="Button" android:visibility="gone" /> <Button android:id="@+id/btn_1" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_margin="5dp" android:layout_weight="1" android:text="Button 1" /> <Button android:id="@+id/btn_2" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_margin="5dp" android:layout_weight="1" android:text="Button 2" /> <Button android:id="@+id/btn_3" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_margin="5dp" android:layout_weight="1" android:text="Button 3" /> </LinearLayout> STEP 2: Declear the Button's in Global variables like below Button btn_1,btn_2,btn_3,dummy_btn; Initialize Button's like below btn_1 = (Button) findViewById(R.id.btn_1); btn_2 = (Button) findViewById(R.id.btn_2); btn_3 = (Button) findViewById(R.id.btn_3); dummy_btn = (Button) findViewById(R.id.dummy_btn); STEP 3: btn_1 ClickListener like below btn_1.setOnClickListener(new OnClickListener(){ @Override public void onClick(View v) { // Get all currently displaying text of Button final String btn_1_string = btn_1.getText().toString().trim(); final String btn_2_string = btn_2.getText().toString().trim(); final String btn_3_string = btn_3.getText().toString().trim(); // First Button Left to Right Animation TranslateAnimation anim = new TranslateAnimation(0f, 200f, 0f, 0f); anim.setDuration(2000); btn_1.startAnimation(anim); // Second Button Left to Right Animation anim = new TranslateAnimation(0f, 200f, 0f, 0f); anim.setDuration(2000); btn_2.startAnimation(anim); // Third Button Left to Right Animation anim = new TranslateAnimation(0f, 200f, 0f, 0f); anim.setDuration(2000); btn_3.startAnimation(anim); btn_3.setVisibility(View.INVISIBLE); dummy_btn.setText(btn_3.getText().toString().trim()); // Dummy Button Left to Right Animation for like marquee animation dummy_btn.setVisibility(View.VISIBLE); anim = new TranslateAnimation(-200f, 0f, 0f, 0f); anim.setDuration(2000); dummy_btn.startAnimation(anim); // After 2000 Millis displaying text Handler handler = new Handler(); handler.postDelayed(new Runnable() { @Override public void run() { btn_2.setText(btn_1_string); btn_3.setText(btn_2_string); btn_1.setText(btn_3_string); btn_3.setVisibility(View.VISIBLE); dummy_btn.setVisibility(View.GONE); } }, 2000); } }); and the remaining two Button ClickListener btn_2.setOnClickListener(new OnClickListener(){ @Override public void onClick(View v) { // TODO Auto-generated method stub btn_1.performClick(); } }); btn_3.setOnClickListener(new OnClickListener(){ @Override public void onClick(View v) { // TODO Auto-generated method stub btn_1.performClick(); } });
Kostya Khuta at Stack Overflow Visit the source
Related Q & A:
- How to add buttons and panels in frame in java?Best solution by Stack Overflow
- How to make background animation?Best solution by Stack Overflow
- How to remove buttons in Yahoo Tool bar?Best solution by Yahoo! Answers
- How to make change in a team?Best solution by Yahoo! Answers
- How to make a moving animation?Best solution by goanimate.com
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.