Android animation on clicking a gridview item
I am using a list of music albums with an adapter and a gridView. When the item`s, I mean the play button, clicked the "Img" animation at the bottom of the screen. The problem is that the "img animation" moves back the side of the gridview items, not the top. I want to implement this animation like kugou music player here .
Here is my code: Gridview list.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:id="@+id/animImg"
android:layout_width="20dp"
android:layout_height="20dp"
android:src="@drawable/anim"
android:scaleType="fitCenter"
android:adjustViewBounds="true"/>
<GridView
android:id="@+id/gridView"
android:numColumns="2"
android:gravity="center"
android:horizontalSpacing="7dp"
android:verticalSpacing="7dp"
android:stretchMode="columnWidth"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</GridView>
Gridview view.xml elements
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@android:color/white"
android:weightSum="11">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="10">
<ImageView
android:id="@+id/albumImg"
android:layout_width="match_parent"
android:layout_height="120dp"
android:src="@drawable/album"
android:scaleType="fitXY"
android:adjustViewBounds="true"/>
<ImageView
android:id="@+id/albumPlayBtn"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_gravity="top|right"
android:src="@drawable/play_button"
android:scaleType="fitCenter"
android:adjustViewBounds="true"/>
</FrameLayout>
<TextView
android:id="@+id/albumName"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="0.5"
android:gravity="center"
android:textSize="24sp"
android:textColor="@android:color/black"
android:layout_gravity="center"
android:text="Album name"/>
<TextView
android:id="@+id/artistName"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="0.5"
android:gravity="center"
android:textSize="16sp"
android:textColor="@android:color/darker_gray"
android:layout_gravity="center"
android:text="Artist name"/>
and my doAnimation method:
public void doAnimation(int[] originalPos) {
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(animImg.getWidth(), animImg.getHeight());
animImg.setLayoutParams(lp);
Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
int width = size.x;
int height = size.y;
TranslateAnimation anim = new TranslateAnimation(originalPos[0], originalPos[0],
originalPos[1], height);
anim.setDuration(3000);
animImg.startAnimation(anim);
anim.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
}
@Override
public void onAnimationRepeat(Animation animation) {
}
});
}
Thanks in advance!
+3
source to share