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. echart.js在vue中使用

    以前可能写过,懒得去翻了,再写一次 1,安装echarts   导入到页面 import echarts from 'echarts'; 2.在生命周期里面做初始化 data(){ return{ t ...

  2. xib中的label加边框

    选中xib中的label,在右边栏的第三个标签页中第三项是User Defined Runtime Attributes 添加一个keyPath,keyPath值为layer.borderWidth, ...

  3. pc send instructor pc ad

     1. #include <string.h> #include <intrins.h> // 加入此头文件后,可使用_nop_库函数 #define MAIN_Fosc 11 ...

  4. CentOS6.9安装Python-3.6.3

    CentOS6.9上默认安装的python版本是2.6的.因为系统自带的python会被系统很多软件环境依赖使用,所以不要卸载原来的Python版本,根据需要进行安装新版本即可,本人此处安装的是3.6 ...

  5. JNI 记

    Java Native Interface(JNI)从零开始详细教程  ================================================================ ...

  6. html 2

    一.列表 信息资源的一种展示形式 二.列表的分类 1.有序列表 <ol> <li>列表项1</li> <li>列表项2</li> </ ...

  7. BASH 基本语法

    本节内容 1.  什么是shell script 2.  变量 3.  运算符 4.  流程控制 5.  函数 6.  计划任务 crontab 一  什么是shell script 将OS命令堆积到 ...

  8. WPF实现特殊统计图

    效果图: ActiveFunItem.xaml代码: <UserControl x:Class="SunCreate.Vipf.Client.UI.ActiveFunItem" ...

  9. Rgb2Gray

    GPU上运行的函数又称为Kernel,用__global__修饰 调用Kernel函数时,用FunctionCall<<<block_shape, thread_shape, int ...

  10. 从navicat中导入sql文件过大:Got a packet bigger than 'max_allowed_packet' bytes

    失败背景:刚才通过navicat向本地mysql数据库中导入sql文件.第一个sql文件(多个表)大小为967M,导入成功: 第二个sql(单个表)大小为50.1M,导入失败. 1.在navicat中 ...