Android整个布局缩放

来源:互联网 发布:个股融资融券数据查询 编辑:程序博客网 时间:2024/06/02 04:48

效果图

效果图

在整个界面的跟布局设置一个ID,在Activity中获取这个控件

<?xml version="1.0" encoding="utf-8"?><android.support.constraint.ConstraintLayout    xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:app="http://schemas.android.com/apk/res-auto"    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:id="@+id/content"    android:background="#F00"    tools:context="com.xiaoge.scaledemo.MainActivity">    <TextView        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="Hello World!"        android:textSize="36sp"        app:layout_constraintBottom_toBottomOf="parent"        app:layout_constraintLeft_toLeftOf="parent"        app:layout_constraintRight_toRightOf="parent"        app:layout_constraintTop_toTopOf="parent"/></android.support.constraint.ConstraintLayout>

Activity中的代码

public class MainActivity extends AppCompatActivity {    private ConstraintLayout content;    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);        initView();        scaleWindow();    }    private void initView() {        content = (ConstraintLayout) findViewById(R.id.content);    }    private void scaleWindow() {        /** 设置缩放动画 */        final ScaleAnimation animation = new ScaleAnimation(1f, 0.9f, 1f, 0.9f,                Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);// 从相对于自身0.5倍的位置开始缩放,也就是从控件的位置缩放        animation.setDuration(2000);//设置动画持续时间        /** 常用方法 */        //animation.setRepeatCount(int repeatCount);//设置重复次数        animation.setFillAfter(true);//动画执行完后是否停留在执行完的状态        //animation.setStartOffset(long startOffset);//执行前的等待时间        content.setAnimation(animation);        /** 开始动画 */        animation.startNow();    }}
1 0
原创粉丝点击