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. LAB4

    鼠标放上去可以看文件说明,exception则在exception中处理 文件头里面穿信息,为404 out.flush();把以前的全部冲掉了,所以需要放在后面

  2. spring入门--spring入门案例

    spring是一个框架,这个框架可以干很多很多的事情.感觉特别吊.但是,对于初学者来说,很难理解spring到底是干什么的.我刚开始的时候也不懂,后来就跟着敲,在后来虽然懂了,但是依然说不明白它到底是 ...

  3. zabbix自定义监控

    有的时候zabbix提供的监控项目,不能满足我们生产环境下的监控需求,此时我们就要按照zabbix的规范自定义监控项目,达到监控的目的 zabbix_get:模拟zabbix_server和agent ...

  4. poj2240

    一个关于套利的题,就是判断是否有正环,我这里是用的SPFA,只要判断出来一种货币初始为1,最后变得大于1就代表是正环,要注意一下最后对vector的清空,当时从1开始清空,导致wa了两次,找了半天,尽 ...

  5. python参数

    1.形参变量和实参 形参变量:只有在被调用时才分配内存单元,在调用结束时,即释放所分配的内存单元,因此,形参只在函数内有效,函数调用结束返回主调用函数后则不能再使用该形参变量. 实参:可以是常量,变量 ...

  6. ABP框架系列之三十:(Javascript-API-Javascript-API)

    ASP.NET Boilerplate provides a set of objects and functions that are used to make javascript develop ...

  7. clickhouse安装使用文档

    Clickhouse简介 Clickhouse是什么 1. 开源的列存储数据库管理系统 2. 支持线性扩展 3. 简单方便 4. 高可靠性 5. 容错(支持多主机异步复制,可以跨多个数据中心部署. 单 ...

  8. HTML学习总结(作业五)

    1:HTML简介 超文本标记语言,标准通用标记语言下的一个应用.是 网页制作必备的编程语言“超文本”就是指页面内可以包含图片.链接,甚至音乐.程序等非文字元素.超文本标记语言的结构包括“头”部分(英语 ...

  9. bzoj4555(多项式求逆解法)

    //和以前写的fft不太一样,可能是因为要取模?? #include<iostream> #include<cstring> #include<cmath> #in ...

  10. a标签使用href=”javascript:void(0); 在火狐浏览器跟chrome 不兼容

    使用如下方式的链接.在Chrome中点击后行为符合预期,但在IE下会新开标签卡(根据参考资料,Firefox中有相同问题).<a href=”javascript:void(0);” targe ...