[英]How to slide up and slide down with animation in android
I have layout file 我有布局文件
<LinearLayout
android:id="@+id/linear_search"
android:orientation="vertical"
android:background="#fee102"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:textSize="20sp"
android:id="@+id/search"
android:gravity="left|center"
android:paddingLeft="10dp"
android:paddingTop="15dp"
android:paddingBottom="15dp"
android:drawablePadding="10dp"
android:textColor="#5b5a52"
android:text="What - When - Where?"
android:drawableLeft="@drawable/ic_search_black_24px"
android:background="#ffed64"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<EditText
android:visibility="gone"
android:textSize="20sp"
android:id="@+id/what"
android:gravity="left|center"
android:paddingLeft="10dp"
android:paddingTop="15dp"
android:paddingBottom="15dp"
android:drawablePadding="10dp"
android:textColor="#5b5a52"
android:text="What?"
android:background="#ffed64"
android:layout_marginTop="10dp"
android:layout_marginBottom="5dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<EditText
android:visibility="gone"
android:textSize="20sp"
android:id="@+id/when"
android:gravity="left|center"
android:paddingLeft="10dp"
android:paddingTop="15dp"
android:paddingBottom="15dp"
android:drawablePadding="10dp"
android:textColor="#5b5a52"
android:text="When?"
android:background="#ffed64"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<EditText
android:visibility="gone"
android:textSize="20sp"
android:id="@+id/where"
android:gravity="left|center"
android:paddingLeft="10dp"
android:paddingTop="15dp"
android:paddingBottom="15dp"
android:drawablePadding="10dp"
android:textColor="#5b5a52"
android:text="Where?"
android:background="#ffed64"
android:layout_marginTop="5dp"
android:layout_marginBottom="10dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
I want to slide down when search text view click and then search text view gone and all other edit text view visible with animation how to do this? 当单击搜索文本视图时,我想向下滑动,然后消失搜索文本视图,并且所有其他可编辑动画的可见文本视图如何执行此操作?
how to do in java please tell me the whole code for this 如何在Java中执行操作,请告诉我整个代码
public void slideUp(View view) {
view.setVisibility(View.VISIBLE);
TranslateAnimation animate = new TranslateAnimation(
0, // fromXDelta
0, // toXDelta
view.getHeight() , // fromYDelta
0); // toYDelta
animate.setDuration(500);
animate.setFillAfter(true);
view.startAnimation(animate);
}
public void slideDown(final View view) {
TranslateAnimation animate = new TranslateAnimation(
0, // fromXDelta
0, // toXDelta
0, // fromYDelta
view.getHeight()); // toYDelta
animate.setDuration(500);
animate.setFillAfter(true);
view.startAnimation(animate);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
view.setVisibility(View.GONE);
}
}, 500);
}
You can use ObjectAnimator. 您可以使用ObjectAnimator。
You can animate in any direction (x or y). 您可以沿任何方向(x或y)设置动画。
Android reference link https://developer.android.com/reference/android/animation/ObjectAnimator.html Android参考链接https://developer.android.com/reference/android/animation/ObjectAnimator.html
make a slide_down.xml file in anim folder and copy the following code 在anim文件夹中创建slide_down.xml文件,然后复制以下代码
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="1500"
android:fromYDelta="5"
android:toYDelta="90%" />
for slide_up.xml 对于slide_up.xml
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="1500"
android:fromYDelta="90%"
android:toYDelta="0" />
now in your java code use the following code 现在在您的Java代码中使用以下代码
Animation slideUpAnimation = AnimationUtils.loadAnimation(getApplicationContext(),
R.anim.slide_up_animation);
lastly cast it to your imageview or whatever u are using.. 最后将其投射到您的imageview或您正在使用的任何内容。
imageView.startAnimation(slideUpAnimation);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.