public class MainActivity extends AppCompatActivity {
private TextView kuandu;
float curTranslationX;
float width;
float height;
private Button out;
private Button in;
   private View view;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
kuandu = (TextView) findViewById(R.id.kuandu);
out = (Button) findViewById(R.id.out);
in = (Button) findViewById(R.id.in);
view = findViewById(R.id.view);
out.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
goOut();
}
});
in.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
goIn();
}
}); WindowManager manager = this.getWindowManager();
DisplayMetrics outMetrics = new DisplayMetrics();
manager.getDefaultDisplay().getMetrics(outMetrics);
width = outMetrics.widthPixels;
height = outMetrics.heightPixels;
kuandu.setText("宽度是:" +width+ ",高度是" + height); } private void goOut() {
curTranslationX = view.getTranslationX();
ObjectAnimator animator = ObjectAnimator.ofFloat(view, "translationX", curTranslationX, width);
animator.setDuration(1000);
animator.start(); } private void goIn() {
curTranslationX = view.getTranslationX();
ObjectAnimator animator = ObjectAnimator.ofFloat(view, "translationX", curTranslationX, 0);
animator.setDuration(1000);
animator.start(); } }
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="vertical"
tools:context="com.example.laoyimou.imagetest.MainActivity"> <Button
android:id="@+id/out"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="out" /> <Button
android:id="@+id/in"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="in" /> <TextView
android:id="@+id/kuandu"
android:layout_width="match_parent"
android:layout_height="wrap_content" /> <View
android:id="@+id/view"
android:layout_width="match_parent"
android:layout_height="80dp"
android:background="@color/colorPrimary" /> </LinearLayout>

获取屏幕宽度,将view移出屏幕再移动回来的更多相关文章

  1. 微信小程序(6)--获取屏幕宽度及弹窗滚动与页面滚动冲突

    1.获取屏幕宽度,并赋值给view <view class="ships-img" style="height:{{windowWidth}}px;"&g ...

  2. 微信小程序如何获取屏幕宽度

    微信小程序如何获取屏幕宽度 方法1: imageLoad: function () { this.setData({ imageWidth: wx.getSystemInfoSync().window ...

  3. Android获取屏幕宽度高度

    方法一: WindowManager wm = (WindowManager) this .getSystemService(Context.WINDOW_SERVICE); int width = ...

  4. Android获取屏幕宽度、高度的4种方法

    记录学习之用,有相同的问题可以参考 方法一: WindowManager wm = (WindowManager) this .getSystemService(Context.WINDOW_SERV ...

  5. Android获取屏幕宽度的4种方法

    方法一: WindowManager wm = (WindowManager) this.getSystemService(Context.WINDOW_SERVICE); int width = w ...

  6. android学习8——获取view在屏幕上的绝对坐标

    获取view在屏幕上的绝对坐标在调试时候非常有用. 看如下代码 public class AbsolutePosActivity extends Activity { @Override public ...

  7. Android 获取View在屏幕中的位置【转】

    Android 获取View在屏幕中的位置 https://blog.csdn.net/lonely_fireworks/article/details/7849643

  8. Access中出现改变字段“自己主动编号”类型,不能再改回来!(已解决)

    Access中出现改变字段"自己主动编号"类型,不能再改回来! (已解决) 一次把access中的自增字段改成了数值,再改回自增时,提示:在表中输入了数据之后,则不能将不论什么字段 ...

  9. WPF: ShowDialog() 切换到其他应用窗口后,再切换回来无法让子窗口总在最上方

    按说ShowDialog()是模态窗口,应该在主窗口的上方,但是打开其他应用窗口再切换回来的时候,发现子窗口不见了,主窗口又不能操作. 另外子窗口设置成不在任务栏显示,只能通过Alt-Tab来切换到子 ...

随机推荐

  1. 考研部分概念和流程(若不全和错误可提示我补充,另考研帮app推荐)

    上大学必须经过全国统一高考,而就读硕士研究生的途径相对而言要多一些,也更灵活一些.已经工作的人,除了放弃工作报考研究生以外,还可以不脱产申请攻读学位,或申请单独考试.不脱产申请攻读学位,通俗的讲,就是 ...

  2. Ueditor 前后端分离实现文件上传到独立服务器

    关于Ueditor 前后端分离实现文件上传到独立服务器,在网上搜索确实遇到大坑,不过还好遇到了 虚若影 最终实现了,在此感谢!虚若影的原文博客网址:http://www.cnblogs.com/hpn ...

  3. JVM思考-ClassLoader.loadClasshe和Class.forName区别

    JVM思考-ClassLoader.loadClasshe和Class.forName区别 目录:JVM总括:目录 见博客第四节:JVM总括四-类加载过程.双亲委派模型.对象实例化过程

  4. springboot restful接口服务异常处理

    一.spring boot中默认的错误处理机制 二.自定义的异常处理

  5. spring boot + spring batch 读数据库文件写入文本文件&读文本文件写入数据库

    好久没有写博客,换了一家新公司,原来的公司用的是spring,现在这家公司用的是spring boot.然后,项目组布置了一个任务,关于两个数据库之间的表同步,我首先想到的就是spring batch ...

  6. BZOJ4386[POI2015]Wycieczki / Luogu3597[POI2015]WYC - 矩乘

    Solution 想到边权为$1$的情况直接矩乘就可以得出长度$<=t$ 的路径条数, 然后二分check一下即可 但是拓展到边权为$2$,$3$ 时, 需要新建节点 $i+n$ 和 $i+2n ...

  7. Android 多线程编程

    Android 多线程编程 //1.多线程 进程:操作系统的多道程序 线程:同一个程序的多条路径 //2.创建多线程程序 创建一个类extends Thread 重写run方法 在main方法中创建对 ...

  8. js 新增标签、标签属性

    var table = document.getElementById('content_list'); console.log(ret.data.length); ;i<ret.data.le ...

  9. 第37章:MongoDB-集群--Replica Sets(副本集)---单机的搭建

    ①创建副本集 1:先创建几个存放数据的文件夹,比如在前面的dbs下面创建db1,db2,db3: 同理在前面的logs下面创建logs1,logs2,logs3 2:在启动MongoDB服务器的时候, ...

  10. Django积木块一——验证码

    验证码 在github中搜验证码,那个有使用文档 # pip install django-simple-captcha==0.4.6 # setting app captcha # url url( ...