Reputation: 25
I'm trying to animate an imageview in height, with a var that I'll receive from a database later on. Checked stack and other sites but did not find a suitable answer, do not want do it using xml. here is some code i already have:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<ImageView
android:id="@+id/background"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/enkelzijdig" />
<ImageView
android:id="@+id/bar1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="75dp"
android:layout_marginTop="150dp"
android:src="@drawable/animatiebalk" />
</RelativeLayout>
**than where the magic should happen:**
package com.example.grafiek;
import android.app.Activity;
import android.os.Bundle;
import android.view.Window;
import android.widget.ImageView;
public class MainActivity extends Activity{
ImageView balk1;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);
balk1 = (ImageView)findViewById(R.id.balk1);
}
public void ScaleAnimation (float fromX, float toX, float fromY, float toY){
no clue what to do
}
}
Upvotes: 0
Views: 139
Reputation: 893
Use the animation to do that---
Animation fadeInFromTopAnimation = AnimationUtils
.loadAnimation(ActivityName.this, R.anim.slide_up);
fadeInFromTopAnimation
.setAnimationListener(new AnimationListener() {
public void onAnimationStart(Animation anim) {
}
public void onAnimationEnd(Animation anim) {
imageView.setVisibility(View.GONE);
}
public void onAnimationRepeat(Animation anim) {
}
});
imageView.startAnimation(fadeInFromTopAnimation);
where you have to make the following slide_up.xml in anim folder---
<?xml version="1.0" encoding="utf-8"?>
<set
xmlns:android = "http://schemas.android.com/apk/res/android"
android:interpolator = "@android:anim/linear_interpolator">
<alpha
android:fromAlpha = "1"
android:toAlpha = "0"
android:duration = "100">
</alpha>
<scale
android:fromXScale = "1"
android:fromYScale = "1"
android:toXScale = "1"
android:toYScale = "0"
android:pivotX = "50%"
android:pivotY = "0%"
android:duration = "100">
</scale>
</set>
Upvotes: 1