我正在尝试使用我以后从数据库收到的var来设置高度的imageview动画。检查堆栈和其他网站但没有找到合适的答案,不希望使用xml。这是我已经拥有的一些代码:
<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
}
}
答案 0 :(得分:0)
使用动画来做到这一点---
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);
你必须在动画文件夹---
中制作以下slide_up.xml<?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>