Android从下往上滑动的布局,在ConstraintLayout中,android向上/向下滑动 SurfaceView_android_开发99编程知识库...

我使用约束布局为 3 subviews的root:TextView

按钮

SurfaceView ( 视图,可见性= 已经消失)

单击按钮时,SurfaceView显示为( 可见性。可见性= 可见):

Y = - SurfaceView.height

到:

Y = 0

当我在按钮上单击第二次时,SurfaceView会消失( 视图。可见性= 已经删除):

Y = 0

到:

Y = - SurfaceView.height

xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:app="http://schemas.android.com/apk/res-auto"

android:layout_width="match_parent"

android:layout_height="match_parent">

android:id="@+id/title"

android:layout_width="0dp"

android:layout_height="wrap_content"

android:text="Animation"

android:textSize="30sp"

android:gravity="center"

app:layout_constraintTop_toTopOf="parent"

android:layout_marginTop="8dp"

android:layout_marginLeft="8dp"

app:layout_constraintLeft_toLeftOf="parent"

android:layout_marginRight="8dp"

app:layout_constraintRight_toRightOf="parent"

android:layout_marginStart="8dp"

android:layout_marginEnd="8dp"/>

android:id="@+id/display_btn"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Dsiplay"

android:textSize="30sp"

android:layout_marginTop="8dp"

app:layout_constraintTop_toBottomOf="@+id/title"

app:layout_constraintBottom_toBottomOf="parent"

android:layout_marginBottom="8dp"

android:layout_marginRight="8dp"

app:layout_constraintRight_toRightOf="parent"

android:layout_marginLeft="8dp"

app:layout_constraintLeft_toLeftOf="parent"

android:layout_marginStart="8dp"

android:layout_marginEnd="8dp"/>

android:id="@+id/animation_view"

android:layout_width="0dp"

android:layout_height="150dp"

android:visibility="gone"

app:layout_constraintLeft_toLeftOf="parent"

app:layout_constraintRight_toRightOf="parent"

app:layout_constraintTop_toTopOf="parent"

android:layout_marginTop="8dp"

android:layout_marginLeft="8dp"

android:layout_marginRight="8dp"

android:layout_marginStart="8dp"

android:layout_marginEnd="8dp"/>

MainActivity:public class MainActivity extends Activity {

boolean isVisible = false;

@Override

protected void onCreate(@Nullable Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

findViewById(R.id.display_btn).setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View view) {

isVisible =!isVisible;

if(isVisible){

/*

* Start Animation slide to down

* */

findViewById(R.id.animation_view).animate()

. translationY(0)

. setListener(new AnimatorListenerAdapter() {

@Override

public void onAnimationStart(Animator animation) {

super.onAnimationStart(animation);

findViewById(R.id.animation_view).setY(-findViewById(R.id.animation_view).getHeight());

findViewById(R.id.animation_view).setVisibility(View.VISIBLE);

}

});

}

else {

/*

* Start Animation slide to up

* */

findViewById(R.id.animation_view).animate()

. translationY(-findViewById(R.id.animation_view).getHeight())

. setListener(new AnimatorListenerAdapter() {

@Override

public void onAnimationStart(Animator animation) {

super.onAnimationStart(animation);

}

@Override

public void onAnimationEnd(Animator animation) {

super.onAnimationEnd(animation);

findViewById(R.id.animation_view).setVisibility(View.GONE);

}

});

}

}

});

}

}

当我点击第一次它不工作的时候。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值