在代码中实现控件消失后另外的控件动画移动到消失控件的位置

来源:互联网 发布:神武3手游狮驼数据 编辑:程序博客网 时间:2024/05/27 14:14

创建一个项目:

activity文件:

public class ZxSignInActivity extends AppCompatActivity implements View.OnClickListener {    TextView text, text1;    View v1;    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_zx_sign_in);        text = (TextView) findViewById(R.id.text);        text1 = (TextView) findViewById(R.id.text1);        v1 = findViewById(R.id.view);        text.setOnClickListener(this);        text1.setOnClickListener(this);    }    @Override    public void onClick(View view) {        switch (view.getId()) {            case R.id.text:                break;            case R.id.text1:                text.setVisibility(View.GONE);                break;        }    }}

关键代码:android:animateLayoutChanges=”true”

在布局中根目录下加上这句就好了。

<?xml version="1.0" encoding="utf-8"?><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"    **android:animateLayoutChanges="true"**    tools:context=".ZxAnimation.ZxSignInActivity">    <TextView        android:id="@+id/text"        android:layout_marginTop="@dimen/activity_horizontal_margin"        android:layout_width="match_parent"        android:drawableTop="@mipmap/ic_launcher"        android:drawablePadding="10dp"        android:layout_height="wrap_content"        android:gravity="center"        android:text="已完成签到"/>    <TextView        android:id="@+id/text1"        android:layout_below="@+id/text"        android:layout_width="match_parent"        android:layout_height="280dp"        android:background="#33ddff"/></RelativeLayout>
0 0
原创粉丝点击