Animating gridlayout from gone to visible - android

Gridlayout (it is centered inside a relative layout)
<GridLayout
android:id="#+id/ticketLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/pile"
android:visibility="gone"
android:animateLayoutChanges="true" >
<!-- some content -->
Now when I make it visible
ticketLayout.setVisibility(View.VISIBLE);
it just appears, there is no animation at all. Am I missing something?

You need to animate your View.
You can do it, for example, like this:
mticketLayout.setAlpha(0f);
mticketLayout.setVisibility(View.VISIBLE);
// Animate the content view to 100% opacity, and clear any animation
// listener set on the view.
mticketLayout.animate()
.alpha(1f)
.setDuration(mShortAnimationDuration)
.setListener(null);
Take a look at the Android Training: http://developer.android.com/training/animation/crossfade.html

There is no default animation for this. In order to achieve what you want I think you need to play an animation on the alpha property of your gridview.
Depending on what minimum API you want to support you can use the old animation system, or the new one, or even use NineOldAndroids.
The animateLayoutChange flag specifies that if you dynamically add a view inside this grid view, the system will have to play a default animation. (Most likely a fading effect) It doesn't help for the grid view itself.

Related

Android - Fading Layout Border

I am working on an android app and I have a scrollview, and in that, I have a linear layout in the main activity. I want to have the top and bottom borders of the linear layout to be "faded
" so as the user scrolls down the child views in the layout will "fade out" as the go down.
Here is an example of what I am trying to achieve in my linearlayout or scrollview (the "fading bottom border".
Thanks for you help!
Subby
You can do that by using the following attributes in the ScrollView.
android:requiresFadingEdge="vertical"
android:fadingEdgeLength="20dp"
If you want it on devices before API14, you need to use the following:
android:requiresFadingEdge="vertical"
android:fadingEdgeLength="20dp"
NOTE: This is actually discouraged as it is seen to have a negative performance impact on devices.
At the bottom of your layout, you can have a view above the listView, and set Gradient Color for the view, and also make it semitransparent, then you can have the effect you want.

How can i after animated view move a views below? (without using Animation class)

For animation i use a ViewPropertyAnimator.
mAnimatedView.animate().translationYBy(50).start();
Before translation:
After translation:
I want buttons to stay below AnimatedView (according to the mentioned above illustrations it is not right now). There is only one idea that comes to my mind: animate buttons too, but i am sure it is not the best solution. Maybe there is a method that recalculates all layout while animation, that i have missed?
Add Buttons to xml before AnimatedView:
<Button ...>
<AnimatedView ...>

Android how to make fading edges appear on Horizontal List View

I have used HorizontalListView which does the functioning of ListView but in horizontal manner. This HorizontalListView doesn't show fadingEdge on scroll to first and last items of the list.So I need to add fadingEdge on this view.I may find the scroll of first and last child,but I don't have any idea on how to show fadingEdge when scroll reaches to first and last child as done in ListView.Further I have already added
<com.ui.widgets.HorizontalListView
android:id="#+id/horizontalListView"
android:layout_width="fill_parent"
android:layout_height="120dip"
android:gravity="left"
android:fadingEdge="horizontal"/>
And it doesn't have any effect.So could you point me in the right direction on how to programmatically add fadingEdge to the HorizontalListView
From the documentation for fadingEdge:
This attribute is deprecated and will be ignored as of API level 14 (ICE_CREAM_SANDWICH). Using fading edges may introduce noticeable performance degradations and should be used only when required by the application's visual design. To request fading edges with API level 14 and above, use the android:requiresFadingEdge attribute instead.
Try using the android:overScrollMode attribute.
Just add
android:overScrollMode="always"
to your View.
android:overScrollMode can have three values: "always", "never", "ifContentScrolls".

Android placing imageView through Code

I want on the initialization of my activity in android to set the position of some imageView's
by code.
Lets say I have five cards displayed on the screen, all placed in (0,0) by me in the XML.
I want to calculate the screen size (easy to do) and then place the first card at 0.2height , 0.2 width the second one 0.4height, 0.4 width, ETC.
I want to do it through code so i could change some constants in the future and the rest of the changes will apply automatically
Thanks.
Create a LinearLayout container view in your layout, and then use code to add your new View to it
<LinearLayout
android:id="#+id/container"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
And then:
((ViewGroup)findViewById(R.id.container)).addView(myImageView);
try to use "findViewById()" to inflate some parental layouts,
"new ImageView()" to construct new Views and ".add(myImageView)" to add them.
In your code u can use all kinds of setters for the imageview...
(btw: more details would be great, the question is kinda ambiguous)

is it possible to do transition animations when changing views in the same activity?

Suppose I have 2 XML files and my activity will setContentView the appropriate one based on some button press from the user. Is it possible to change the transition animation for the changing of content view?
So far I see super.overridePendingTransition() which is suitable for starting new activities, however my example does not start a new activity, it just changes the layout in the current one.
Mathias Lin has explained it very well.
You can always use default stock animations supplied by Android framework.
Heres an example code:
boolean isFirstXml=evaluatingConditionFunction();
LayoutInflater inflator=getLayoutInflater();
View view=inflator.inflate(isFirstXml?R.layout.myfirstxml:R.layout.myseconxml, null, false);
view.startAnimation(AnimationUtils.loadAnimation(this, android.R.anim.slide_out_right));
setContentView(view);
Call this from any of your activity which holds your Parent View.
For custom animations you can visit developer docs. Heres the documentation link.
Yes, you can apply an animation on almost any view you like. Just via view.startAnimation(animation);
Take the outer viewgroup of your respective layout (content view) and apply the animation to it. Depending what kind of animation you want to do, it might make sense to inflate/load both layouts but hide one of them and then swap. Please specify what kind of transition you have in mind.
For example: if you do an alpha transition, you would run the alphaAnimation on the current layout, when when the animation ends (AnimationListener), you set the content view to the new layout, and fade the content back in, via another alphaAnimation.
A better solution is using ViewFlipper: it is a FrameLayout, that can do animations when changing the views.
<ViewFlipper
android:id="#+id/[your_id_here]"
android:inAnimation="..."
android:outAnimation="..."
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<RelativeLayout
<!--Your first layout -->
</RelativeLayout>
<RelativeLayout
<!--Your second layout -->
</RelativeLayout>
</ViewFlipper>
Then, switch the views with setDisplayedChild(int) or showNext() or showPrevious. If you want to have different animation for left and right movement, you have to set inAnimation and outAnimation in the code before transition.
More complete example is here.

Categories

Resources