获取屏幕宽度,将view移出屏幕再移动回来
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移出屏幕再移动回来的更多相关文章
- 微信小程序(6)--获取屏幕宽度及弹窗滚动与页面滚动冲突
1.获取屏幕宽度,并赋值给view <view class="ships-img" style="height:{{windowWidth}}px;"&g ...
- 微信小程序如何获取屏幕宽度
微信小程序如何获取屏幕宽度 方法1: imageLoad: function () { this.setData({ imageWidth: wx.getSystemInfoSync().window ...
- Android获取屏幕宽度高度
方法一: WindowManager wm = (WindowManager) this .getSystemService(Context.WINDOW_SERVICE); int width = ...
- Android获取屏幕宽度、高度的4种方法
记录学习之用,有相同的问题可以参考 方法一: WindowManager wm = (WindowManager) this .getSystemService(Context.WINDOW_SERV ...
- Android获取屏幕宽度的4种方法
方法一: WindowManager wm = (WindowManager) this.getSystemService(Context.WINDOW_SERVICE); int width = w ...
- android学习8——获取view在屏幕上的绝对坐标
获取view在屏幕上的绝对坐标在调试时候非常有用. 看如下代码 public class AbsolutePosActivity extends Activity { @Override public ...
- Android 获取View在屏幕中的位置【转】
Android 获取View在屏幕中的位置 https://blog.csdn.net/lonely_fireworks/article/details/7849643
- Access中出现改变字段“自己主动编号”类型,不能再改回来!(已解决)
Access中出现改变字段"自己主动编号"类型,不能再改回来! (已解决) 一次把access中的自增字段改成了数值,再改回自增时,提示:在表中输入了数据之后,则不能将不论什么字段 ...
- WPF: ShowDialog() 切换到其他应用窗口后,再切换回来无法让子窗口总在最上方
按说ShowDialog()是模态窗口,应该在主窗口的上方,但是打开其他应用窗口再切换回来的时候,发现子窗口不见了,主窗口又不能操作. 另外子窗口设置成不在任务栏显示,只能通过Alt-Tab来切换到子 ...
随机推荐
- react项目的ant-design-mobile的使用
现在测试一下ant-design-mobile的使用,引用一个Button 没有样式 这个问题是没有引入样式 解决方法有两种 这种方法自己弄不出来,然后用另外一种方法 引入样式: import 'an ...
- [leetcode]47. Permutations全排列(给定序列有重复元素)
Given a collection of numbers that might contain duplicates, return all possible unique permutations ...
- Spring Boot+Quartz实现一个实时管理的定时任务
转载 https://www.cnblogs.com/wujiwen/p/9615120.html 项目实践过程中碰到一个动态管理定时任务的需求:针对每个人员进行信息的定时更新,具体更新时间可随时调整 ...
- Python开发——【循环】语句
while循环 while 条件: # 要执行的循环体 # 如果条件为真,那么循环体则执行 # 如果条件为假,那么循环体不执行 死循环 count = 0 while True:# 条件永远为真 pr ...
- 20172325 2018-2019-2 《Java程序设计》第九周学习总结
20172325 2018-2019-2 <Java程序设计>第九周学习总结 教材学习内容总结 图的定义 图是由顶点集(VertexSet)和边集(EdgeSet)组成,针对图G,顶点集和 ...
- 2019.02.17 spoj Query on a tree V(链分治)
传送门 题意简述: 给你一棵nnn个黑白点的树,初始全是黑点. 现在支持给一个点换颜色或者求整颗树中离某个点最近的白点跟这个点的距离. 思路: 考虑链分治维护答案,每个链顶用一个堆来维护答案,然后对于 ...
- python模块:configparser
"""Configuration file parser. A configuration file consists of sections, lead by a &q ...
- C#中Equals()和= =(等于号)区别
在这里,首先得告诉大家,在C#中,不管是 == ,还是 Equals() 我们都是可以重写的.所以,在具体选择使用两者时,还是得根据这两个方法的具体实现逻辑来选择. 值类型的比较 对于值类型来说,两者 ...
- OC 中property的使用
property在使用的时候需要在其前面加上@符号,需要将其写在类的头文件中 当在定义一个对象的属性变量时,例如定义一个Person类中的name属性,可定义为: @property (nonatom ...
- freeRTOSConfig.h文件对FreeRTOS进行系统配置
FreeRTOS内核是高度可定制的,使用配置文件FreeRTOSConfig.h进行定制.每个FreeRTOS应用都必须包含这个头文件,用户根据实际应用来裁剪定制FreeRTOS内核.这个配置文件是针 ...