am facing a strange problem, I have generated my layout file using RelativeLayout. however while reading top of one of the child's present in it is being returned as zero,which is causing my whole animation logic go for toss.
My idea is to animate them from bottom of screen, to there initial position. below is my code, any help from you all will be highly appreciated.
My layout file.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:paddingLeft="35dp"
android:paddingRight="35dp" >
<LinearLayout
android:id="#+id/msgs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="35dp"
android:layout_marginTop="25dp"
android:orientation="vertical" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:gravity="center_horizontal"
android:text="#string/share"
android:textColor="#android:color/black"
android:textSize="26dp"
android:typeface="monospace" />
<TextView
android:layout_width="match_parent"
android:layout_height="48dp"
android:layout_gravity="top"
android:maxLines="3"
android:text="#string/share_message"
android:textColor="#android:color/black"
android:textSize="14dp"
android:typeface="sans" />
</LinearLayout>
<ImageView
android:id="#+id/view_twitter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_above="#id/msgs"
android:layout_marginEnd="25dp"
android:scaleType="fitCenter"
android:src="#drawable/circle_twitter" />
<ImageView
android:id="#+id/view_facebook"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#id/msgs"
android:layout_marginEnd="25dp"
android:scaleType="fitCenter"
android:layout_toStartOf="#id/view_twitter"
android:src="#drawable/facebook_circle" />
<ImageView
android:id="#+id/view_google"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#id/msgs"
android:layout_marginEnd="25dp"
android:layout_toEndOf="#id/view_twitter"
android:scaleType="fitCenter"
android:src="#drawable/google_circle" />
</RelativeLayout>
My Fragment code, where am animating them
import android.animation.Animator;
import android.animation.Animator.AnimatorListener;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.graphics.Point;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.Display;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.AccelerateDecelerateInterpolator;
public class IntroFragmentThird extends Fragment{
View google;
View twitter;
View facebook;
View messagePanel;
int screenHeight;
int screenWidth;
int offset;
float beginPoint;
#Override
public void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
Display display = getActivity().getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
screenWidth = size.x;
screenHeight = size.y;
offset = screenHeight + 200; // start from 200px below screen height
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.intro3_layout, container, false);
google = view.findViewById(R.id.view_google);
facebook = view.findViewById(R.id.view_facebook);
twitter = view.findViewById(R.id.view_twitter);
messagePanel = view.findViewById(R.id.msgs);
google.setVisibility(View.GONE); // Initial view visibility will be gone
facebook.setVisibility(View.GONE);
twitter.setVisibility(View.GONE);
beginPoint = twitter.getTop(); // this is coming as ZERO
return view;
}
#Override
public void onResume() {
// TODO Auto-generated method stub
super.onResume();
System.out.println("#### Top : " + beginPoint);
playScreenAnimation();
}
public void playScreenAnimation(){
facebook.clearAnimation();
facebook.setVisibility(View.GONE);
facebook.clearAnimation();
facebook.setVisibility(View.GONE);
facebook.clearAnimation();
facebook.setVisibility(View.GONE);
ObjectAnimator anim1 = ObjectAnimator.ofFloat(facebook, "y", offset , beginPoint);
anim1.setInterpolator(new AccelerateDecelerateInterpolator());
anim1.setDuration(1000);
anim1.setStartDelay(1000);
anim1.addListener(new AnimatorListener(){
#Override
public void onAnimationStart(Animator animation) {
facebook.setVisibility(View.VISIBLE);
}
#Override
public void onAnimationEnd(Animator animation) {
// TODO Auto-generated method stub
}
#Override
public void onAnimationCancel(Animator animation) {
// TODO Auto-generated method stub
}
#Override
public void onAnimationRepeat(Animator animation) {
// TODO Auto-generated method stub
}
});
ObjectAnimator anim2 = ObjectAnimator.ofFloat(twitter, "y", offset , beginPoint);
anim2.setInterpolator(new AccelerateDecelerateInterpolator());
anim2.setDuration(1000);
anim2.addListener(new AnimatorListener(){
#Override
public void onAnimationStart(Animator animation) {
twitter.setVisibility(View.VISIBLE);
}
#Override
public void onAnimationEnd(Animator animation) {
// TODO Auto-generated method stub
}
#Override
public void onAnimationCancel(Animator animation) {
// TODO Auto-generated method stub
}
#Override
public void onAnimationRepeat(Animator animation) {
// TODO Auto-generated method stub
}
});
ObjectAnimator anim3 = ObjectAnimator.ofFloat(google, "y", offset , beginPoint);
anim3.setInterpolator(new AccelerateDecelerateInterpolator());
anim3.setDuration(1000);
anim3.setStartDelay(1000);
anim3.addListener(new AnimatorListener(){
#Override
public void onAnimationStart(Animator animation) {
google.setVisibility(View.VISIBLE);
}
#Override
public void onAnimationEnd(Animator animation) {
// TODO Auto-generated method stub
}
#Override
public void onAnimationCancel(Animator animation) {
// TODO Auto-generated method stub
}
#Override
public void onAnimationRepeat(Animator animation) {
// TODO Auto-generated method stub
}
});
AnimatorSet set = new AnimatorSet();
set.playTogether(anim2,anim1,anim3);
set.start();
}
}
Here is screenshot of, initial state of views (those three fb, g+, twitter circles are being animated)
Alright I solved it, instead of using object animator, i ended up using view animation, and animating views considering there relative positions.
facebook.clearAnimation();
facebook.setVisibility(View.INVISIBLE);
google.clearAnimation();
google.setVisibility(View.INVISIBLE);
twitter.clearAnimation();
twitter.setVisibility(View.INVISIBLE);
TranslateAnimation anim1 = new TranslateAnimation(Animation.RELATIVE_TO_SELF,0,Animation.RELATIVE_TO_SELF,0
,Animation.RELATIVE_TO_SELF,offset,Animation.RELATIVE_TO_SELF,0);
anim1.setDuration(1000);
anim1.setInterpolator(new AccelerateDecelerateInterpolator());
anim1.setAnimationListener(new AnimationListener(){
#Override
public void onAnimationStart(Animation animation) {
facebook.setVisibility(View.VISIBLE);
}
#Override
public void onAnimationEnd(Animation animation) {
// TODO Auto-generated method stub
}
#Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}
});
TranslateAnimation anim2 = new TranslateAnimation(Animation.RELATIVE_TO_SELF,0,Animation.RELATIVE_TO_SELF,0
,Animation.RELATIVE_TO_SELF,offset,Animation.RELATIVE_TO_SELF,0);
anim2.setDuration(750);
//anim2.setStartOffset(500);
anim2.setInterpolator(new AccelerateDecelerateInterpolator());
anim2.setAnimationListener(new AnimationListener(){
#Override
public void onAnimationStart(Animation animation) {
twitter.setVisibility(View.VISIBLE);
}
#Override
public void onAnimationEnd(Animation animation) {
// TODO Auto-generated method stub
}
#Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}
});
TranslateAnimation anim3 = new TranslateAnimation(Animation.RELATIVE_TO_SELF,0,Animation.RELATIVE_TO_SELF,0
,Animation.RELATIVE_TO_SELF,offset,Animation.RELATIVE_TO_SELF,0);
anim3.setDuration(750);
anim3.setStartOffset(500);
anim3.setInterpolator(new AccelerateDecelerateInterpolator());
anim3.setAnimationListener(new AnimationListener(){
#Override
public void onAnimationStart(Animation animation) {
google.setVisibility(View.VISIBLE);
}
#Override
public void onAnimationEnd(Animation animation) {
// TODO Auto-generated method stub
}
#Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}
});
twitter.startAnimation(anim2);
facebook.startAnimation(anim1);
google.startAnimation(anim3);
Related
I am developing an app to show chat head.
I have to implement translate animation on chat head, but it is not animating.
TranslateAnimation trans = new TranslateAnimation(0,
windowManager.getDefaultDisplay().getWidth() / 2, 0,
windowManager.getDefaultDisplay().getHeight());
trans.setFillAfter(false);
trans.setDuration(1000);
view.setAnimation(trans);
trans.setAnimationListener(new AnimationListener() {
#Override
public void onAnimationStart(Animation animation) {
}
#Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}
#Override
public void onAnimationEnd(Animation animation) {
}
});
You have to start animation on view:
view.startAnimation(trans);
I want do a animate scroll like Jquery´s (in this web page works when you click in top menu´s options) in android. is it possible? I have seen that exists scrollTo but is possible to do with animation and not like jumps. Thank you very much.
Using ObjectAnimator, This is a sample for scrolling to top :
public void scroolToTop() {
int x = 0;
int y = 0;
ObjectAnimator xTranslate = ObjectAnimator.ofInt(mScrollView, "scrollX", x);
ObjectAnimator yTranslate = ObjectAnimator.ofInt(mScrollView, "scrollY", y);
AnimatorSet animators = new AnimatorSet();
animators.setDuration(1000L);
animators.playTogether(xTranslate, yTranslate);
animators.addListener(new AnimatorListener() {
#Override
public void onAnimationStart(Animator arg0) {
// TODO Auto-generated method stub
}
#Override
public void onAnimationRepeat(Animator arg0) {
// TODO Auto-generated method stub
}
#Override
public void onAnimationEnd(Animator arg0) {
// TODO Auto-generated method stub
}
#Override
public void onAnimationCancel(Animator arg0) {
// TODO Auto-generated method stub
}
});
animators.start();
}
I am trying to do a TranslateAnimation but don't work properly the layout apear and disapear but didn't do any animation. How could I solve this?
The java code is this:
private void initComponents() {
ImageView postIV = (ImageView) findViewById(R.id.post_view_activity_image_iv);
CropBottonTransformation cropBottomTransformation = new CropBottonTransformation();
Picasso.with(context).load(bundle.getString(Constants.POST_IMAGE))
.centerCrop().fit().placeholder(R.drawable.home_placeholder)
.into(postIV);
TextView postTitleTV = (TextView) findViewById(R.id.post_view_activity_title_tv);
postTitleTV.setText(bundle.getString(Constants.POST_TITLE));
ObservableScrollView scroll = (ObservableScrollView) findViewById(R.id.post_view_activity_scroll);
scroll.setScrollViewListener(this);
hidenOptionsLL = (LinearLayout) findViewById(R.id.post_view_activity_slide_options);
hidenOptionsHeight = hidenOptionsLL.getHeight();
slideRL = (RelativeLayout) findViewById(R.id.post_view_activity_slide_rl);
}
...
#Override
public void onScrollChanged(ObservableScrollView scrollView, int x, int y,
int oldx, int oldy) {
if (y > oldy) {
if (sliding == false) {
// Animation animation =
// AnimationUtils.loadAnimation(context,
// R.anim.slide_in_out);
Animation animation = new TranslateAnimation(0, 0,
hidenOptionsHeight, 0);
animation.setInterpolator(new AccelerateInterpolator(1.0f));
animation.setDuration(600);
hidenOptionsLL.startAnimation(animation);
animation.setAnimationListener(new AnimationListener() {
#Override
public void onAnimationStart(Animation animation) {
sliding = true;
}
#Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}
#Override
public void onAnimationEnd(Animation animation) {
sliding = false;
hidenOptionsLL.setVisibility(View.GONE);
}
});
}
} else if (y < oldy) {
if (sliding == false) {
// Animation animation =
// AnimationUtils.loadAnimation(context,
// R.anim.slide_in_out);
Animation animation = new TranslateAnimation(0, 0, 0,
hidenOptionsHeight);
hidenOptionsLL.setVisibility(View.VISIBLE);
animation.setInterpolator(new AccelerateInterpolator(1.0f));
animation.setDuration(600);
hidenOptionsLL.startAnimation(animation);
animation.setAnimationListener(new AnimationListener() {
#Override
public void onAnimationStart(Animation animation) {
sliding = true;
}
#Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}
#Override
public void onAnimationEnd(Animation animation) {
sliding = false;
}
});
}
}
}
The layout is this:
<LinearLayout
android:id="#+id/post_view_activity_slide_options"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/white"
android:orientation="horizontal"
android:visibility="gone" >
<ImageButton
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#android:color/transparent"
android:src="#android:drawable/arrow_down_float" />
<ImageButton
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#android:color/transparent"
android:src="#android:drawable/arrow_up_float" />
<ImageButton
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#android:color/transparent"
android:src="#android:drawable/ic_delete" />
<ImageButton
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#android:color/transparent"
android:src="#android:drawable/btn_radio" />
</LinearLayout>
I don't find any solution. I want that it works like the options that appear on the bottom of the google search app.
Slideinleft.xml
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromXDelta="100%p" android:toXDelta="0%p"
android:duration="#android:integer/config_shortAnimTime"/>
Slideinright.xml
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromXDelta="-100%p" android:toXDelta="0%p"
android:duration="#android:integer/config_shortAnimTime" />
Slideoutleft.xml
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromXDelta="0" android:toXDelta="-100%p"
android:duration="#android:integer/config_shortAnimTime" />
Slideoutright.xml
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromXDelta="0" android:toXDelta="100%p"
android:duration="#android:integer/config_shortAnimTime" />
use when go one activity to other.
overridePendingTransition(R.anim.slide_in_right,
R.anim.slide_out_right);
It sounds like this library might help you:
https://github.com/flavienlaurent/discrollview?utm_source=Android+Weekly&utm_campaign=2daec38d18-Android_Weekly_86&utm_medium=email&utm_term=0_4eb677ad19-2daec38d18-337293613
But otherwise, you're going to want to set fillEnabled fillBefore and fillAfter to true
The problem is that when I ask for the height at first time the view isn't visible an the value of the height was 0:
I did this:
ImageButton minusLetterIB = (ImageButton) findViewById(R.id.post_view_activity_minus_leters_ib);
hidenOptionsHeight = minusLetterIB.getDrawable().getIntrinsicHeight();
and changed the animation to hide an show the layout:
#Override
public void onScrollChanged(ObservableScrollView scrollView, int x, int y,
int oldx, int oldy) {
if (oldy - y > 20) {
if (sliding == false) {
if (slideRL.getVisibility() == View.GONE) {
Animation animation = new TranslateAnimation(0, 0,
-hidenOptionsHeight, 0);
animation.setInterpolator(new AccelerateInterpolator(1.0f));
animation.setDuration(400);
slideRL.startAnimation(animation);
animation.setAnimationListener(new AnimationListener() {
#Override
public void onAnimationStart(Animation animation) {
sliding = true;
slideRL.setVisibility(View.VISIBLE);
}
#Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}
#Override
public void onAnimationEnd(Animation animation) {
sliding = false;
if (firstTimeSlideUp) {
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
LayoutParams.MATCH_PARENT,
(int) hidenOptionsHeight);
FrameLayout extraLL = new FrameLayout(context);
extraLL.setBackgroundColor(getResources()
.getColor(android.R.color.white));
scrollLL.addView(extraLL, 0, params);
firstTimeSlideUp = false;
}
}
});
}
}
} else if (oldy - y < -20) {
if (sliding == false) {
Log.d("hiding view", "y " + y + " oldy " + oldy);
if (slideRL.getVisibility() == View.VISIBLE) {
Animation animation = new TranslateAnimation(0, 0, 0,
-hidenOptionsHeight);
animation.setInterpolator(new AccelerateInterpolator(1.0f));
animation.setDuration(400);
slideRL.startAnimation(animation);
animation.setAnimationListener(new AnimationListener() {
#Override
public void onAnimationStart(Animation animation) {
sliding = true;
}
#Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}
#Override
public void onAnimationEnd(Animation animation) {
sliding = false;
slideRL.setVisibility(View.GONE);
}
});
}
}
}
}
I try to set ViewHelper.setPivotY(test, 0); in method onClick() but it doesn't work. The animation still scale to the centerY. Here is my code. I don't know where I am wrong?
public class NewClassTest extends Activity{
LinearLayout test;
FrameLayout content;
Button btn;
boolean toggle = true;
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.test_activity);
test = (LinearLayout) findViewById(R.id.test);
content = (FrameLayout) findViewById(R.id.content);
content.setVisibility(View.INVISIBLE);
btn = (Button) findViewById(R.id.button1);
btn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
// ViewHelper.setPivotY(test, 0); does not work
runAnimation(toggle);
toggle = !toggle;
}
});
ViewHelper.setPivotY(test, 0); // work
}
private void runAnimation(boolean in){
AnimatorSet animSet = new AnimatorSet();
ObjectAnimator anim = null, anim2 = null;
// ViewHelper.setPivotY(test, 0); also does not work
if(in){
anim = ObjectAnimator.ofFloat(test, "scaleY", 1, 1 - (((float)content.getHeight()) / ((float) test.getHeight())));
anim2 = ObjectAnimator.ofFloat(content, "translationY", content.getHeight(), 0);
animSet.addListener(new Animator.AnimatorListener() {
#Override
public void onAnimationStart(Animator animation) {
// TODO Auto-generated method stub
content.setVisibility(View.VISIBLE);
}
#Override
public void onAnimationRepeat(Animator animation) {
// TODO Auto-generated method stub
}
#Override
public void onAnimationEnd(Animator animation) {
// TODO Auto-generated method stub
}
#Override
public void onAnimationCancel(Animator animation) {
// TODO Auto-generated method stub
}
});
}else {
anim = ObjectAnimator.ofFloat(test, "scaleY", 1 - ((float)content.getHeight()) / ((float) test.getHeight()), 1);
anim2 = ObjectAnimator.ofFloat(content, "translationY", 0, content.getHeight());
animSet.addListener(new Animator.AnimatorListener() {
#Override
public void onAnimationStart(Animator animation) {
// TODO Auto-generated method stub
}
#Override
public void onAnimationRepeat(Animator animation) {
// TODO Auto-generated method stub
}
#Override
public void onAnimationEnd(Animator animation) {
// TODO Auto-generated method stub
content.setVisibility(View.INVISIBLE);
}
#Override
public void onAnimationCancel(Animator animation) {
// TODO Auto-generated method stub
}
});
}
animSet.setDuration(1000).play(anim2).with(anim);
animSet.start();
}
Thank for your help!.
Happen to me also. test it on HTC One S with android 4.1 and that wasn't worked, but in Samsung Galaxy I with android 2.2 it worked as expected.
Changed it to ViewHelper.setPivotY(test, 0.00000001f); solved it =\
Don't know if it's a bug of HTC, android or nineoldandroids
I want to create one button/layout object dynamically from the object that exist on the current layout and want to handle both differently..
Here is my code that I implemented..
declared globally
Button btnStart, btnButton1, btnButton2, btnButton3;
and in OnCreate()
btnStart = (Button) findViewById(R.id.btnStart);
btnButton1 = (Button) findViewById(R.id.Button1);
btnButton2 = (Button) findViewById(R.id.Button2);
btnButton3 = btnButton1; // Problem comes here.
I want to create btnButton3 dynamically same as btnButton1. On clicking the
btnStart I am running animations for btnButton1, btnButton2 and btnButton3.
Now the issue is btnButton2 running animation fine.. but btnButton1 is not animating
and instead btnButton3 is animating.
Here's my complete code..
public class TweenAnimationActivity extends Activity {
/** Called when the activity is first created. */
Button btnStart, btnButton1, btnButton2, btnButton3;
FrameLayout mainLayout;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mainLayout = (FrameLayout) findViewById(R.id.flMain);
WindowManager wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
Display display = wm.getDefaultDisplay();
int width = display.getWidth();
int height = display.getHeight();
Log.e("Dimension", "Width : " + width + " Height : " + height);
btnStart = (Button) findViewById(R.id.btnStart);
btnButton1 = (Button) findViewById(R.id.Button1);
btnButton2 = (Button) findViewById(R.id.Button2);
btnButton3 = btnButton1;
// btnButton3.setLayoutParams(relativeParams);
final Animation animation = new TranslateAnimation(0, 0, 0,
height - 220);
animation.setDuration(5000);
animation.setFillAfter(true);
animation.setAnimationListener(new AnimationListener() {
#Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub
btnButton1.setText("Moving");
}
#Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}
#Override
public void onAnimationEnd(Animation animation) {
// TODO Auto-generated method stub
btnButton1.setText("Moved");
}
});
final Animation animation1 = new TranslateAnimation(0, 0, 0,
-(height - 220));
// animation1.setStartOffset(1000);
animation1.setDuration(5000);
animation1.setFillAfter(true);
animation1.setAnimationListener(new AnimationListener() {
#Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub
btnButton2.setText("Moving");
}
#Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}
#Override
public void onAnimationEnd(Animation animation) {
// TODO Auto-generated method stub
btnButton2.setText("Moved");
}
});
// final Animation animation2 = new TranslateAnimation(0, 0, -(width - 220),
// height - 220);
final Animation animation2 = new TranslateAnimation(0, 0, (width - 220),
height - 220);
animation2.setDuration(5000);
animation2.setFillAfter(true);
animation2.setAnimationListener(new AnimationListener() {
#Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub
btnButton3.setText("MovingCopied");
}
#Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}
#Override
public void onAnimationEnd(Animation animation) {
// TODO Auto-generated method stub
btnButton3.setText("MovedCopied");
}
});
btnStart.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
btnButton1.startAnimation(animation);
btnButton2.startAnimation(animation1);
btnButton3.startAnimation(animation2);
}
});
}
}
any here's my layout..
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/flMain"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<Button
android:id="#+id/btnStart"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Start" />
<Button
android:id="#+id/Button1"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_gravity="top|right"
android:text="Button1" />
<Button
android:id="#+id/Button2"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_gravity="bottom|right"
android:text="Button2" />
</FrameLayout>
In your code, btnButton3 = btnButton1, you have not created button3 object just created a reference of button1.
try
btnButton3 = new Button(this)
btnButton3.setLayoutParams(btnButton1.getLayoutParams());
mainLayout.addView(btnButton3);
and for better tutorial you can look here.