How to easily view the plugin in Android?

I ran into a problem when I expanded the 320 * 50 view to full screen.

If I deploy it directly, it works, but the action is very cool, and I think this is not a very good user interface. So first I hide the view, then expand it and after two seconds show the view again.

TextView.setVisibility(VIEW.INVISIBLE); ViewGroup.LayoutParams lp = TextView.getLayoutParams(); lp.width = ViewGroup.LayoutParams.FILL_PARENT; lp.height = ViewGroup.LayoutParams.FILL_PARENT; //after two seconds handler.postDelay(new Show(),2000); class Show implements Runnable{ @Override public void run(){ TextView.setVisibility(VIEW.VISIBLE); } } 

So, I left two seconds for the application to expand the view. Then after two seconds the image will reappear. I expect the view to expand to full screen. But actually it is not. A view does an extension action after it is displayed, and not for the two seconds that it hides.

+4
source share
1 answer

I know that it is very late to answer this question, but Iโ€™ll just tell you how I chose the animation of layout changes for those in need.

Android has a special Animation class called ScaleAnimation where we can smoothly expand or collapse views.

Show view by expanding diagonally:

 ScaleAnimation expand = new ScaleAnimation( 0, 1.0f, 0, 1.0f, Animation.RELATIVE_TO_PARENT, 0, Animation.RELATIVE_TO_PARENT, 0); expand.setDuration(250); view.startAnimation(expand) 

where the constructor is used:

 ScaleAnimation(float fromX, float toX, float fromY, float toY, int pivotXType, float pivotXValue, int pivotYType, float pivotYValue) 

This way you can change the values โ€‹โ€‹accordingly.

For example, the following example will animate the horizontal view:

 ScaleAnimation expand = new ScaleAnimation( 0, 1.1f, 1f, 1f, Animation.RELATIVE_TO_PARENT, 0, Animation.RELATIVE_TO_PARENT, 0); expand.setDuration(250); 

You can change from fromX , to toX , from fromY toY to toY .

For example, if a view is displayed and you just need to expand it, place from fromX and fromY to 1.0f and toX toY as appropriate.

Now, using the same class, you can create a cooler effect to display the view by expanding the view a bit and then reducing it to its original size. An AnimationSet will be used for this. So this would create a kind of bubble effect.

The following is an example of creating a bubble effect to display a view:

 AnimationSet expandAndShrink = new AnimationSet(true); ScaleAnimation expand = new ScaleAnimation( 0, 1.1f, 0, 1.1f, Animation.RELATIVE_TO_PARENT, 0, Animation.RELATIVE_TO_PARENT, 0); expand.setDuration(250); ScaleAnimation shrink = new ScaleAnimation( 1.1f, 1f, 1.1f, 1f, Animation.RELATIVE_TO_PARENT, 0, Animation.RELATIVE_TO_PARENT, 0); shrink.setStartOffset(250); shrink.setDuration(120); expandAndShrink.addAnimation(expand); expandAndShrink.addAnimation(shrink); expandAndShrink.setFillAfter(true); expandAndShrink.setInterpolator(new AccelerateInterpolator(1.0f)); view.startAnimation(expandAndShrink); 
0
source

Source: https://habr.com/ru/post/1444358/


All Articles