LayoutTransition does not work on adding the onActivityResult () view

I want to achieve an animation of the shift of views to the right when adding a new view.

I am using LayoutTransition Animation LayoutTransition.APPEARING. I add a new view at the 0th position of the linear layout.

It works fine, except in one case where a view is added from onActivityResult ().

When I run an Activity for the result and try to add a view to the onActivityResult () method, the view is added, however the LayoutTransition animation works.

Scenario 1: Action A starts action B for the result. Action B setResult () and finish () without any action. In this case, the LayoutTransition animation works fine.

Scenario 2: Action A starts action B for the result. In operation B there is a button. When you click Action B setResult () and finish (). In this case, the LayoutTransition animation does not work.

You need to enter data about where I am mistaken, or a workaround to achieve the animation.

Activity A

private LinearLayout ll; private Button b, addbutton, setResultButton; private LayoutTransition transitioner; private Animator defaultAppearingAnim; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.test); ll = (LinearLayout) findViewById(R.id.ll); transitioner = new LayoutTransition(); defaultAppearingAnim = transitioner .getAnimator(LayoutTransition.APPEARING); transitioner.setAnimator(LayoutTransition.APPEARING, defaultAppearingAnim); ll.setLayoutTransition(transitioner); /*Adds Buttons to Linear Layout*/ addbutton = (Button) findViewById(R.id.button1); addbutton.setOnClickListener(this); /*Adds Buttons to Linear Layout on onActivityResult method*/ setResultButton = (Button) findViewById(R.id.button2); setResultButton.setOnClickListener(this); /*Dummy Button Added here*/ for (int i = 0; i < 2; i++) { Button b = new Button(this); b.setText("B " + i); ll.addView(b); } } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { // Result from Activity B we are adding Button to LinearLayout super.onActivityResult(requestCode, resultCode, data); Button b = new Button(this); b.setText("RT"); ll.addView(b, 0); } @Override public void onClick(View v) { if (v == setResultButton) { Intent intent = new Intent(this, ResultActivity.class); startActivityForResult(intent, 0); } else if (v == addbutton) { Button b = new Button(this); b.setText("T"); ll.addView(b, 0); } } 

Activity B

 @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.result); /* SCENARIO 1: LayoutTransition works if the activity setResult and finish setResult(0); finish(); */ /* SCENARIO 2: Here the LayoutTransition animation doesnt work*/ Button setResultButton = (Button) findViewById(R.id.button11); setResultButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub setResult(0); finish(); } }); } 
+4
source share
1 answer

Got a job

Solution for scenario 2:

Here in this case, I added a view using the post () method

 ll.post(new Runnable() { @Override public void run() { // TODO Auto-generated method stub Button b = new Button(ActivityA.this); b.setText("RT"); ll.addView(b, 0); } }); 
+1
source

All Articles