项目效果:

项目结构:

ListAdapter.java

package com.waterflow.myanimationtest1;import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;import java.util.ArrayList;
import java.util.List;public class ListAdapter extends BaseAdapter {private Context context;private LayoutInflater inflater;private List<String> names = new ArrayList<>();public ListAdapter(Context context){inflater = LayoutInflater.from(context);names.add("山峰");names.add("雪山");names.add("海滩");names.add("绿叶");}@Overridepublic int getCount() {return names.size();}@Overridepublic Object getItem(int i) {return null;}@Overridepublic long getItemId(int i) {return 0;}@Overridepublic View getView(int i, View view, ViewGroup viewGroup) {Holder holder;if(view == null){holder = new Holder();view = inflater.inflate(R.layout.listitem_img,null);holder.name = view.findViewById(R.id.name);view.setTag(holder);}else {holder = (Holder) view.getTag();}holder.name.setText(names.get(i));return view;}class Holder{TextView name;}
}

ViewWrapper.java

package com.waterflow.myanimationtest1;import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.widget.LinearLayout;public class ViewWrapper {private View view;private LinearLayout.LayoutParams params;private int originwidth,originheight;public ViewWrapper(View view){this.view = view;params = (LinearLayout.LayoutParams) view.getLayoutParams();originwidth = view.getContext().getResources().getDisplayMetrics().widthPixels;originheight = view.getContext().getResources().getDisplayMetrics().heightPixels;Log.d("view-"+view.getId(),originwidth+"x"+originheight);}int getWidth(){return params.width < 0 ? originwidth : params.width;}int getHeight(){return params.height < 0 ? originheight : params.height;}void setWidth(float width){if(width == originwidth){params.width = -1;params.setMargins(0,0,0,0);}else{params.width = (int)width;}view.setLayoutParams(params);}void setHeight(float height){params.height = (int) height;view.setLayoutParams(params);}int getOriginwidth(){return originwidth;}int getOriginheight(){return originheight;}void setMarginRight(float right){params.setMargins(0,0,(int)right,0);view.setLayoutParams(params);}int getMarginRight(){return params.rightMargin;}
}

MainActivity.java

package com.waterflow.myanimationtest1;import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AppCompatActivity;import android.animation.Animator;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.annotation.SuppressLint;
import android.content.DialogInterface;
import android.graphics.drawable.AnimationDrawable;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.AnimationUtils;
import android.view.animation.ScaleAnimation;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;import org.w3c.dom.Text;public class MainActivity extends AppCompatActivity implements View.OnClickListener{private LinearLayout linear1;private ImageView iv1;private LinearLayout linear2;private ListView list_img;int pressx = 0,pressy = 0 ;ViewWrapper wraplinear1,wrapiv,wraplinear2;private TextView tvTitle;private TextView tvDesc;private Button btnBefore;private Button btnNext;int count = 0;@RequiresApi(api = Build.VERSION_CODES.M)@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);linear1 = (LinearLayout) findViewById(R.id.linear1);iv1 = (ImageView) findViewById(R.id.iv1);linear2 = (LinearLayout) findViewById(R.id.linear2);list_img = (ListView) findViewById(R.id.list_imgs);tvTitle = (TextView) findViewById(R.id.tv_title);tvDesc = (TextView) findViewById(R.id.tv_desc);btnBefore = (Button) findViewById(R.id.btn_before);btnNext = (Button) findViewById(R.id.btn_next);setContent(0);ListAdapter adapter = new ListAdapter(this);list_img.setAdapter(adapter);list_img.setOnItemClickListener(new AdapterView.OnItemClickListener() {@Overridepublic void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {count = i;setContent(i);if(iv1.getAlpha() == 0){AnimatorSet set = new AnimatorSet();//否则复原ObjectAnimator width = ObjectAnimator.ofFloat(wrapiv,"width",wrapiv.getWidth(),wrapiv.getOriginwidth());ObjectAnimator height1 = ObjectAnimator.ofFloat(wrapiv,"height",wrapiv.getHeight(),wrapiv.getOriginwidth()*9/16);ObjectAnimator height2 = ObjectAnimator.ofFloat(wraplinear2,"height",wraplinear2.getHeight(),wraplinear2.getOriginheight()-wrapiv.getOriginwidth()*9/16);ObjectAnimator height3 = ObjectAnimator.ofFloat(wraplinear1,"height",wraplinear1.getHeight(),wraplinear1.getOriginheight());ObjectAnimator alpha = ObjectAnimator.ofFloat(linear2,"alpha",linear2.getAlpha(),1);ObjectAnimator margin = ObjectAnimator.ofFloat(wrapiv,"marginRight",(wrapiv.getOriginwidth()-wrapiv.getWidth())*100/wrapiv.getOriginwidth(),0);ObjectAnimator alpha2 = ObjectAnimator.ofFloat(iv1,"alpha",0,1);set.playTogether(width,height1,height2,height3,alpha,margin,alpha2);set.setDuration(1000);set.start();}}});btnBefore.setOnClickListener(this);btnNext.setOnClickListener(this);wraplinear1 = new ViewWrapper(linear1);wrapiv = new ViewWrapper(iv1);wraplinear2 = new ViewWrapper(linear2);iv1.setOnTouchListener(new View.OnTouchListener() {@Overridepublic boolean onTouch(View view, MotionEvent motionEvent) {switch (motionEvent.getAction()) {case MotionEvent.ACTION_DOWN:pressx = (int) motionEvent.getX();pressy = (int) motionEvent.getY();break;case MotionEvent.ACTION_MOVE:int distancey = (int) (motionEvent.getY() - pressy);int distancex = (int) (motionEvent.getX() - pressx);if(Math.abs(distancey)>200){wraplinear1.setHeight(wraplinear1.getHeight() - distancey / 5);if (wrapiv.getWidth() - distancey/10 < 600){wrapiv.setWidth(600);}else if(wrapiv.getWidth() - distancey/10 > wrapiv.getOriginwidth()){wrapiv.setWidth(wrapiv.getOriginwidth());}else {wrapiv.setWidth(wrapiv.getWidth() - distancey/10);}wrapiv.setHeight(wrapiv.getWidth()*9/16);wrapiv.setMarginRight((wrapiv.getOriginwidth()-wrapiv.getWidth())*100/wrapiv.getOriginwidth());}if(Math.abs(distancex) > 100 && linear2.getAlpha() == 0){wrapiv.setMarginRight(-distancex);}break;case MotionEvent.ACTION_UP:AnimatorSet set = new AnimatorSet();if(wrapiv.getWidth() == 600){//变成最小化形态ObjectAnimator height = ObjectAnimator.ofFloat(wraplinear1,"height",wraplinear1.getHeight(),wrapiv.getHeight()+50);ObjectAnimator alpha = ObjectAnimator.ofFloat(linear2,"alpha",linear2.getAlpha(),0);set.playTogether(height,alpha);}else {//否则复原ObjectAnimator width = ObjectAnimator.ofFloat(wrapiv,"width",wrapiv.getWidth(),wrapiv.getOriginwidth());ObjectAnimator height1 = ObjectAnimator.ofFloat(wrapiv,"height",wrapiv.getHeight(),wrapiv.getOriginwidth()*9/16);ObjectAnimator height2 = ObjectAnimator.ofFloat(wraplinear2,"height",wraplinear2.getHeight(),wraplinear2.getOriginheight()-wrapiv.getOriginwidth()*9/16);ObjectAnimator height3 = ObjectAnimator.ofFloat(wraplinear1,"height",wraplinear1.getHeight(),wraplinear1.getOriginheight());ObjectAnimator alpha = ObjectAnimator.ofFloat(linear2,"alpha",linear2.getAlpha(),1);ObjectAnimator margin = ObjectAnimator.ofFloat(wrapiv,"marginRight",(wrapiv.getOriginwidth()-wrapiv.getWidth())*100/wrapiv.getOriginwidth(),0);set.playTogether(width,height1,height2,height3,alpha,margin);}set.setDuration(1000);set.start();if(wrapiv.getWidth() == 600){AnimatorSet set2 = new AnimatorSet();Log.d("value","rightMargin:"+wrapiv.getMarginRight()+","+(wrapiv.getOriginwidth()/2));if(wrapiv.getMarginRight() > wrapiv.getOriginwidth()/3){ObjectAnimator alpha = ObjectAnimator.ofFloat(iv1,"alpha",1,0);ObjectAnimator margin = ObjectAnimator.ofFloat(wrapiv,"marginRight",wrapiv.getMarginRight(),wrapiv.getOriginwidth());set2.playTogether(alpha,margin);}else{ObjectAnimator margin = ObjectAnimator.ofFloat(wrapiv,"marginRight",wrapiv.getMarginRight(),(wrapiv.getOriginwidth()-wrapiv.getWidth())*100/wrapiv.getOriginwidth());set2.playTogether(margin);}set2.setDuration(1000);set2.start();}break;default:break;}return true;}});}@Overridepublic void onClick(View view) {switch (view.getId()){case R.id.btn_before:count = (count-1)%4;if(count < 0){count = 3;}setContent(count);break;case R.id.btn_next:count = (count+1)%4;setContent(count);break;}}void setContent(int i){int[] pics = {R.drawable.mountain,R.drawable.snowmountain,R.drawable.beach,R.drawable.leaf};String[] titles = {"山峰","雪山","海滩","绿叶"};String[] descs = {"日头将落下那一边天空,还剩有无数云彩,这些云彩阻拦了日头,却为日头的光烘出炫目美丽的颜色。这一边,有一些云彩镶了金边、白边、玛瑙边、淡紫边,如都市中妇人的衣缘,精致而又华丽。云彩无色不备,在空中以一种魔术师的手法,不断的在流动变化。空气因为雨后而澄清,一切景色皆如一人久病新瘥的神气。","玉龙雪山非常高,最高点是3600米高,但是我看不到山顶,因为云把山分成两部分,而山顶是上部,被云抓住。所以我决定坐缆车上山,看看这座3600米高的雪山有多壮观。","站在海滩上,海水像母亲的手,抚摸着你,让你感受到深沉的母爱,海水又是像一只温顺的小狗,安安静静,倚在你的身旁,但有时又有“东临碣石,以观沧海”的叱咤风云。","春天里有一种树叶,它由三片叶子构成,翠绿翠绿的,而且都是椭圆形,有一点长,如果合在一起就像“千手观音”,漂亮极了!如果将它中间一片叶子摘下来它就像英文字母“Y”,也像“yes”的手势,非常好玩。"};iv1.setImageResource(pics[i]);tvTitle.setText(titles[i]);tvDesc.setText(descs[i]);}
}

图片文件在此:



Android模仿youtube的拖拽视频效果相关推荐

  1. Android qq消息气泡实现效果,Android 实现仿QQ拖拽气泡效果的示例

    效果图: 一.实现思路 在列表中默认使用自定义的TextView控件来展示消息气泡,在自定义的TextView控件中重写onTouchEvent方法,然后在DOWN.MOVE.UP事件中分别处理拖拽效 ...

  2. Android仿Ios下拉回弹,Android ReboundScrollView仿IOS拖拽回弹效果

    初衷: 其实github上有很多这种ScrollView的项目,但是不得不说功能太多太乱了,我就只是想要一个简单效果的ScrollView,另外监听下滑动距离而已,想想还是自己写了个. 这里先说下思路 ...

  3. android开发之仿QQ拖拽界面效果(侧滑面板)

    仿QQ拖拽界面效果(侧滑面板),我们一般继承Layout,不会直接去继承ViewGroup,而是继承FrameLayout,为什么五大布局我们偏偏只继承FrameLayout呢? 第一,FrameLa ...

  4. Android仿QQ消息拖拽效果(二)

    前言 本文参考辉哥贝塞尔曲线 - QQ消息汽包拖拽,前面我们使用二阶贝塞尔曲线绘制了拖拽圆点效果Android仿QQ消息拖拽效果(一)(二阶贝塞尔曲线使用),这里我们在此基础之上实现仿QQ消息拖拽爆炸 ...

  5. android qq消息数 拖拽动画,史上最详细仿QQ未读消息拖拽粘性效果的实现

    好久没写文章了,前段时间由于项目代码重构忙了一段时间,现在终于有点时间了就为大家带来一篇关于动画学习的自定义View:类似QQ消息拖拽的效果. 其实QQ当时更新的时候我还没注意到这个小红点是可以拖拽的 ...

  6. android ListView和GridView拖拽移位具体实现及拓展

    关于ListView拖拽移动位置,想必大家并不陌生,比较不错的软件都用到如此功能了.如:搜狐,网易,百度等,但是相比来说还是百度的用户体验较好,不偏心了,下面看几个示例:              首 ...

  7. 贝塞尔曲线(Bezier)之 QQ 消息拖拽动画效果

    博主声明: 转载请在开头附加本文链接及作者信息,并标记为转载.本文由博主 威威喵 原创,请多支持与指教. 本文首发于此   博主:威威喵  |  博客主页:https://blog.csdn.net/ ...

  8. react实现的点击拖拽元素效果

    之前用vue做日程管理组件的时候,用到了点击拖拽的效果,即点击元素,鼠标移动到哪里,元素移动到哪里,鼠标松开,拖拽停止,现在在弄react,于是也在想实现这个效果,经过一番折腾,效果出来了,代码如下: ...

  9. android让字体左右对齐,Android 模仿微信读书文字左右对齐效果

    原标题:Android 模仿微信读书文字左右对齐效果 本文作者 作者:Amter https://www.jianshu.com/p/020786e22a6f 左右对齐的文字效果,很常见,在大多数文章 ...

最新文章

  1. linux系统自带的监控工具
  2. 各纬度气候分布图_读我国一月平均气温分布图,寻找我国冬季气温最高和最低的地方...
  3. 云级Key-value数据库大比较
  4. Python-OpenCV基本操作cv2
  5. Spring MVC 成员变量 request 线程安全问题的讨论
  6. Python 生成账号密码算法
  7. elasticsearch索引的初始化操作以及marvel操作(增删改查),批量查询_mget,批量操作_bulk
  8. 如何将c语言中的文件,急求如何将下列C语言程序数据存储到文件中?
  9. 大数 Buy the tickey玄学
  10. 情感计算在淘宝UGC的应用
  11. 解决VSCode下载慢或下载失败的问题
  12. 单龙芯3A3000-7A1000PMON研究学习-(25)撸起袖子干-再来一杯代码7
  13. 二叉树先序递归遍历,中序递归非递归遍历实验
  14. Camera ITS当中的gain/shutter组合测试
  15. Python 抓取数据并可视化
  16. 2022年终总结与展望
  17. 基本linux性能调优技巧
  18. DRF中的路由Router使用
  19. bi 建模流程图_搞懂PowerBI的数据建模
  20. bt种子自动发布 linux,Linux制作BT种子并获取BT种子信息

热门文章

  1. 转化为五分制的c语言程序,用C语言把百分制转化为五分制
  2. 静态资源部署分析和实验
  3. 【实验技术笔记】Western Blotting 实验操作要点及数据分析
  4. python中functools的partiaethod_设置functools.partial作为Python中的一个实例方法
  5. POE供电 网线 电源 网络情况图
  6. 用Python-opencv快速实现人脸识别功能(从零开始教你)(复制粘贴即可用)
  7. 计算机缓存Cache以及Cache Line详解
  8. RACI职责分配矩阵模型使用详解及案例分析
  9. Python自动化--1.Python环境安装-linux
  10. 7个实用的Python自动化测试框架