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. java_24 FileOutputStream类和FileInputStream类

    1.OutputStream 和InputStream 输入和输出:1.参照物都是java程序来惨遭 2.Input输入,持久化上的数据---->内存 3.Output输出,内存--->硬 ...

  2. java【基础】日期操作

    主要是date类,SimpleDateFormat类以及Calendar类的使用. date表示日期,simpleDateFormat 表示日期格式化,Calendar一般用来做时间的操作,比如加减天 ...

  3. SVN忘记登陆用户

    C:\Users\Yaolz\AppData\Roaming\Subversion\auth 删除里面所有文件

  4. 哪些人才适合转行学习UI设计?

    最近有很多学员问,怎么才知道自己适不适合学习UI设计,在从事IT教育行业多年以来,也确实碰到好多人咨询这个问题,今天就和大家说下,哪些人才适合转行学习UI设计?(转行必看) 1 平面设计师.网页设计师 ...

  5. AX_List

    List list = new List(Types::Class);  CustTable custTable;  while select custTable  {      list.addEn ...

  6. 【ElasticSearch】 安装

    Elasticsearch简介 Elasticsearch 是一个开源的分布式 RESTful 搜索和分析引擎,能够解决越来越多不同的应用场景 官网地址:https://www.elastic.co ...

  7. 数据库-mysql命令

    1.项目过程:概要设计阶段 —— 架构师 任务:技术选型(网络/语言/框架).项目结构(子系统/模块).数据结构(数据特点/内容) 项目中存储数据的方式: (1)服务器内存:存取速度快:非永久存储.容 ...

  8. 返回头部js

    $('.backTop, .backCss').click(function() { var id=$(this).attr('class'); $('html, body').animate({sc ...

  9. tensorflow学习之(六)使用tensorboard展示神经网络的graph

    # 创建神经网络, 使用tensorboard 展示graph import tensorflow as tf import numpy as np import matplotlib.pyplot ...

  10. Linux 第七天

    软件包管理 1.软件包分类 1)源码包(脚本安装包) 优点: l  开源,如果有足够的能力,可以修改源代码 l  可以自由选择所需的功能 l  软件是编译安装,所以更加适合自己的系统,更加稳定也效率更 ...