Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Resizing layouts programmatically (as animation)

I want to resize some layouts in my Activity.

Here is the code of the main XML:

<LinearLayout     android:layout_width="fill_parent"     android:layout_height="fill_parent"     android:layout_weight="1"     android:orientation="vertical" >      <LinearLayout         android:id="@+id/top"         android:layout_width="fill_parent"         android:layout_height="0dip"         android:layout_weight="1"         android:background="#3ee3e3" >     </LinearLayout>      <LinearLayout         android:id="@+id/middle"         android:layout_width="fill_parent"         android:layout_height="fill_parent"         android:layout_weight="1">     </LinearLayout>      <LinearLayout         android:id="@+id/bottom"         android:layout_width="fill_parent"         android:layout_height="0dip"         android:layout_weight="1"         android:background="#fe51e6" >     </LinearLayout> </LinearLayout> 

As you can see, the top and bottom layouts height's is 0, and the middle layout covers all the place.

I want to programmatically decrease the middle layout size, while increase both the top and the bottom layout sizes, till all the layouts have the same height.

I want it to be look like an animation.

How should I do that?

Thanks

like image 430
dor506 Avatar asked Nov 15 '11 17:11

dor506


People also ask

What is layoutanimation in configurenext?

An enumeration of layout properties to be animated to be used in the create method, or in the create / update / delete configs for configureNext. (example usage: LayoutAnimation.Properties.opacity) A set of predefined animation configs to pass into configureNext.

What is a responsive XAML layout?

The foundation of a responsive layout is the appropriate use of XAML layout properties and panels to reposition, resize, and reflow content in a fluid manner. The XAML layout system supports both static and fluid layouts. In a static layout, you give controls explicit pixel sizes and positions.

How to modify the Ui when the window size changes?

However, most UI layouts need further modification when there are significant changes to the window size. For this, you can use visual states. Use visual states to make significant alterations to your UI based on window size or other changes.

How do I set the size of a star in XAML?

In XAML, star values are expressed as * (or n * for weighted star sizing). For example, to specify that one column is 5 times wider than the second column in a 2-column layout, use "5*" and "*" for the Width properties in the ColumnDefinition elements. This example combines fixed, auto, and proportional sizing in a Grid with 4 columns.


1 Answers

I wrote a ResizeAnimation for a similar purpose. It's simple but costly.

Java

    /**      * an animation for resizing the view.      */     public class ResizeAnimation extends Animation {         private View mView;         private float mToHeight;         private float mFromHeight;          private float mToWidth;         private float mFromWidth;          public ResizeAnimation(View v, float fromWidth, float fromHeight, float toWidth, float toHeight) {             mToHeight = toHeight;             mToWidth = toWidth;             mFromHeight = fromHeight;             mFromWidth = fromWidth;             mView = v;             setDuration(300);         }          @Override         protected void applyTransformation(float interpolatedTime, Transformation t) {             float height =                     (mToHeight - mFromHeight) * interpolatedTime + mFromHeight;             float width = (mToWidth - mFromWidth) * interpolatedTime + mFromWidth;             LayoutParams p = mView.getLayoutParams();             p.height = (int) height;             p.width = (int) width;             mView.requestLayout();         }     } 

Kotlin

class ResizeAnimation(     private val view: View,     private val toHeight: Float,     private val fromHeight: Float,     private val toWidth: Float,     private val fromWidth: Float,     duration: Long ) : Animation() {      init {         this.duration = duration     }      override fun applyTransformation(         interpolatedTime: Float,         t: Transformation?     ) {         val height = (toHeight - fromHeight) * interpolatedTime + fromHeight         val width = (toWidth - fromWidth) * interpolatedTime + fromWidth         val layoutParams = view.layoutParams         layoutParams.height = height.toInt()         layoutParams.width = width.toInt()         view.requestLayout()     } } 
like image 92
faylon Avatar answered Sep 26 '22 19:09

faylon