gpt4 book ai didi

java - 我的 ImageView 的动画高度

转载 作者:行者123 更新时间:2023-12-01 14:29:51 26 4
gpt4 key购买 nike

我正在尝试使用稍后从数据库收到的 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


}

}

最佳答案

使用动画来做到这一点——

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);

你必须在anim文件夹中制作以下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>

关于java - 我的 ImageView 的动画高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16938354/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com