我们做table时,常常想做一个滑块的移动效果,来让app显得更加生动,原理很简单,废话不说,直接上code

public class AnimationActivity extends AppCompatActivity {
private Button bt01, bt02, bt03, bt04;
private ImageView view;
int screenWidth;//屏幕宽度
int screenHeight;//屏幕高度
int positionView = 0;//记录滑块的位置 @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_animation); bt01 = (Button) findViewById(R.id.bt01);
bt02 = (Button) findViewById(R.id.bt02);
bt03 = (Button) findViewById(R.id.bt03);
bt04 = (Button) findViewById(R.id.bt04);
view = (ImageView) findViewById(R.id.view); //获取屏幕宽高度
DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
screenWidth = dm.widthPixels / 4;//屏幕宽度的1/4,用来设置滑块的宽度
screenHeight = dm.heightPixels;//屏幕高度,用来设置滑块的宽度 //设置滑块的宽高
ViewGroup.LayoutParams params = view.getLayoutParams();
params.height = screenHeight / 100;
params.width = screenWidth;
view.setLayoutParams(params); bt01.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//参数 1.动画目标view 2.动画移动方式 3.view出发的位置 4.view的目标位置
ObjectAnimator animator = ObjectAnimator.ofFloat(view, "translationX", positionView, 0);
animator.setDuration(300);
animator.start();
//移动后这里要把位置设置为当前的位置
positionView = 0;
}
});
bt02.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//参数 1.动画目标view 2.动画移动方式 3.view出发的位置 4.view的目标位置
ObjectAnimator animator = ObjectAnimator.ofFloat(view, "translationX", positionView, screenWidth);
animator.setDuration(300);
animator.start();
//移动后这里要把位置设置为当前的位置
positionView = screenWidth;
}
});
bt03.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//参数 1.动画目标view 2.动画移动方式 3.view出发的位置 4.view的目标位置
ObjectAnimator animator = ObjectAnimator.ofFloat(view, "translationX", positionView, screenWidth * 2);
animator.setDuration(300);
animator.start();
//移动后这里要把位置设置为当前的位置
positionView = screenWidth * 2;
}
});
bt04.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//参数 1.动画目标view 2.动画移动方式 3.view出发的位置 4.view的目标位置
ObjectAnimator animator = ObjectAnimator.ofFloat(view, "translationX", positionView, screenWidth * 3);
animator.setDuration(300);
animator.start();
//移动后这里要把位置设置为当前的位置
positionView = screenWidth * 3;
}
});
}
}
<?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.teststudio.AnimationActivity"> <LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"> <Button
android:id="@+id/bt01"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="bt" /> <Button
android:id="@+id/bt02"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="bt" /> <Button
android:id="@+id/bt03"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="bt" /> <Button
android:id="@+id/bt04"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="bt" />
</LinearLayout> <ImageView
android:id="@+id/view"
android:layout_width="50dp"
android:layout_height="5dp"
android:background="#563265" />
</LinearLayout>

table滑块的更多相关文章

  1. 在iOS中怎样创建可展开的Table View?(下)

    接上篇:在iOS中怎样创建可展开的Table View?(上) 展开和合拢 我猜这部分可能是你最期望的了,因为本次教程的目标将会在在部分实现.第一次我们设法让顶层的cell,在它们点击的时候展开或者合 ...

  2. 在iOS中怎样创建可展开的Table View?(上)

    原文地址 本文作者:gabriel theodoropoulos 原文:How To Create an Expandable Table View in iOS 原文链接 几乎所有的app都有一个共 ...

  3. 一款基于jQuery可放大预览的图片滑块插件

    今天给大家分享一款基于jQuery可放大预览的图片滑块插件.这款jQuery焦点图插件的特点是可以横向左右滑动图片,并且点击图片可以进行放大预览,唯一的缺陷是这款焦点图并不能循环切换,如果你有较好的J ...

  4. 去除element-ui table表格右侧滚动条的高度

    /* //element-ui table的去除右侧滚动条的样式 */ ::-webkit-scrollbar { width: 1px; height: 1px; } /* // 滚动条的滑块 */ ...

  5. HTML table表头固定

    HTML table表头固定 说说我在最近项目中碰到的css问题吧,作为问题知识集合总结笔记: <!DOCTYPE html> <html> <head> < ...

  6. layui表单使用开关滑块和复选框,渲染后台数据方法

    提示:整个表格要在form标签内 定义开关模板 <div class="layui-form" lay-filter="layuiadmin-app-form-li ...

  7. 【原创】Python 极验滑块验证

    本文仅供学习交流使用,如侵立删! 记一次 极验滑块验证分析并通过 操作环境 win10 . mac Python3.9 selenium.seleniumwire 分析 最近在做的一个项目登录时会触发 ...

  8. 散列表(hash table)——算法导论(13)

    1. 引言 许多应用都需要动态集合结构,它至少需要支持Insert,search和delete字典操作.散列表(hash table)是实现字典操作的一种有效的数据结构. 2. 直接寻址表 在介绍散列 ...

  9. React使用antd Table生成层级多选组件

    一.需求 用户对不同的应用需要有不同的权限,用户一般和角色关联在一起,新建角色的时候会选择该角色对应的应用,然后对应用分配权限.于是写了一种实现的方式.首先应用是一个二级树,一级表示的是应用分组,二级 ...

随机推荐

  1. SQL Server XML 查询

    [参考1] 18个小实例入门SQLServer XML查询 [参考2] 转载---SQL Server XML基础学习之<5>--XQuery(query)

  2. Python集合(set)类型的操作 (转)

    python的set和其他语言类似, 是一个无序不重复元素集, 基本功能包括关系测试和消除重复元素. 集合对象还支持union(联合), intersection(交), difference(差)和 ...

  3. python加密解密算法

    https://www.cnblogs.com/xiao-apple36/p/8744408.html

  4. linux resin 基本站点配置

    进入配置文件目录: [root@linuxidc resin-]# cd /usr/local/resin/conf/ 查看都有哪些配置文件: [root@linuxidc conf]# ls app ...

  5. 目录命令(tree)

    TREE 命令: // 描述: 以图形方式显示驱动器中路径或磁盘的目录结构. // 语法: tree [<Drive>:][<Path>] [/f] [/a] // 参数: / ...

  6. 复制命令(XCOPY)

    XCOPY 命令: // 描述: 将文件或目录(包括子目录)从一个位置复制到另一个位置. // 语法: Xcopy <Source> [<Destination>] [/w] ...

  7. sshpass 使用方法

    首先下载sshpass并且安装 $ tar -zxvf sshpass-1.06.tar.gz $ cd sshpass-1.06 $ ./configure --prefix=/usr/local/ ...

  8. 居于H5的多文件、大文件、多线程上传解决方案

    文件上传在web应用中是比较常见的功能,前段时间做了一个多文件.大文件.多线程文件上传的功能,使用效果还不错,总结分享下. 一. 功能性需求与非功能性需求 要求操作便利,一次选择多个文件进行上传: 支 ...

  9. ScriptOJ-safeGet#99

    const safeGet = (data, path) => { if(!path) return undefined; const pathArr = path.split('.'); le ...

  10. 【python-strip】Python strip()方法

    strip()方法用于移除字符串首尾的指定字符(默认是空格) 比如: str = "0000000this is string example....wow!!!0000000"; ...