Android仿一号店货物详情轮播图动画效果

Android仿一号店货物详情轮播图动画效果,第1张

概述还不是很完全,目前只能点中间图片才能位移,图片外的其他区域没有。。(属性动画),对了,图片加载用得是facebook的一款android图片加载库,感觉非常NB啊,完爆一切。

还不是很完全,目前只能点中间图片才能位移,图片外的其他区域没有。。(属性动画),对了,图片加载用得是facebook的一款androID图片加载库,感觉非常NB啊,完爆一切。

1、先看布局

<?xml version="1.0" enCoding="utf-8"?><relativeLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"  xmlns:tools="http://schemas.androID.com/tools"  androID:layout_wIDth="match_parent"  androID:layout_height="match_parent"  tools:context=".MainActivity">  <ScrollVIEw    androID:ID="@+ID/scrollVIEw"    androID:layout_wIDth="match_parent"    androID:layout_height="match_parent">    <linearLayout      androID:layout_wIDth="match_parent"      androID:layout_height="wrap_content"      androID:background="#bfbfbf"      androID:orIEntation="vertical">      <androID.support.v4.vIEw.VIEwPager        androID:ID="@+ID/vIEwPager"        androID:layout_wIDth="match_parent"        androID:layout_height="300dp" />      <linearLayout        androID:ID="@+ID/ll_bottom_container"        androID:layout_wIDth="match_parent"        androID:layout_height="wrap_content"        androID:background="#ffffff"        androID:orIEntation="vertical">        <linearLayout          androID:layout_wIDth="match_parent"          androID:layout_height="60dp"          androID:gravity="center">          <TextVIEw            androID:layout_wIDth="wrap_content"            androID:layout_height="wrap_content"            androID:gravity="center"            androID:text="Item 1"            androID:textSize="16sp" />        </linearLayout>        <linearLayout          androID:layout_wIDth="match_parent"          androID:layout_height="60dp"          androID:gravity="center">          <TextVIEw            androID:layout_wIDth="wrap_content"            androID:layout_height="wrap_content"            androID:gravity="center"            androID:text="Item 1"            androID:textSize="16sp" />        </linearLayout>        <linearLayout          androID:layout_wIDth="match_parent"          androID:layout_height="60dp"          androID:gravity="center">          <TextVIEw            androID:layout_wIDth="wrap_content"            androID:layout_height="wrap_content"            androID:gravity="center"            androID:text="Item 1"            androID:textSize="16sp" />        </linearLayout>        <linearLayout          androID:layout_wIDth="match_parent"          androID:layout_height="60dp"          androID:gravity="center">          <TextVIEw            androID:layout_wIDth="wrap_content"            androID:layout_height="wrap_content"            androID:gravity="center"            androID:text="Item 1"            androID:textSize="16sp" />        </linearLayout>        <linearLayout          androID:layout_wIDth="match_parent"          androID:layout_height="60dp"          androID:gravity="center">          <TextVIEw            androID:layout_wIDth="wrap_content"            androID:layout_height="wrap_content"            androID:gravity="center"            androID:text="Item 1"            androID:textSize="16sp" />        </linearLayout>        <linearLayout          androID:layout_wIDth="match_parent"          androID:layout_height="60dp"          androID:gravity="center">          <TextVIEw            androID:layout_wIDth="wrap_content"            androID:layout_height="wrap_content"            androID:gravity="center"            androID:text="Item 1"            androID:textSize="16sp" />        </linearLayout>        <linearLayout          androID:layout_wIDth="match_parent"          androID:layout_height="60dp"          androID:gravity="center">          <TextVIEw            androID:layout_wIDth="wrap_content"            androID:layout_height="wrap_content"            androID:gravity="center"            androID:text="Item 1"            androID:textSize="16sp" />        </linearLayout>        <linearLayout          androID:layout_wIDth="match_parent"          androID:layout_height="60dp"          androID:gravity="center">          <TextVIEw            androID:layout_wIDth="wrap_content"            androID:layout_height="wrap_content"            androID:gravity="center"            androID:text="Item 1"            androID:textSize="16sp" />        </linearLayout>        <linearLayout          androID:layout_wIDth="match_parent"          androID:layout_height="60dp"          androID:gravity="center">          <TextVIEw            androID:layout_wIDth="wrap_content"            androID:layout_height="wrap_content"            androID:gravity="center"            androID:text="Item 1"            androID:textSize="16sp" />        </linearLayout>        <linearLayout          androID:layout_wIDth="match_parent"          androID:layout_height="60dp"          androID:gravity="center">          <TextVIEw            androID:layout_wIDth="wrap_content"            androID:layout_height="wrap_content"            androID:gravity="center"            androID:text="Item 1"            androID:textSize="16sp" />        </linearLayout>        <linearLayout          androID:layout_wIDth="match_parent"          androID:layout_height="60dp"          androID:gravity="center">          <TextVIEw            androID:layout_wIDth="wrap_content"            androID:layout_height="wrap_content"            androID:gravity="center"            androID:text="Item 1"            androID:textSize="16sp" />        </linearLayout>      </linearLayout>    </linearLayout>  </ScrollVIEw>  <!-- 辅助作用,用于计算屏幕中间位置 -->  <linearLayout    androID:ID="@+ID/ll_container_scroll"    androID:layout_wIDth="match_parent"    androID:layout_height="match_parent"    androID:background="#bfbfbf"    androID:gravity="center"    androID:orIEntation="horizontal"    androID:visibility="invisible">    <!-- 必须和上面显示的vIEwpager一样高 -->    <androID.support.v4.vIEw.VIEwPager      androID:ID="@+ID/vIEwPager_2"      androID:layout_wIDth="match_parent"      androID:layout_height="300dp" />  </linearLayout></relativeLayout>

2、主界面代码

package com.newair.frescotextdemo;import androID.animation.Animator;import androID.support.v4.vIEw.VIEwPager;import androID.support.v7.app.AppCompatActivity;import androID.os.Bundle;import androID.vIEw.VIEw;import androID.Widget.linearLayout;import androID.Widget.ScrollVIEw;import androID.Widget.Toast;import java.util.ArrayList;import java.util.List;import adapter.MyVIEwPagerAdapter;import utils.ScreenUtils;public class MainActivity extends AppCompatActivity {  private ScrollVIEw scrollVIEw;  private linearLayout ll_container_scroll;//scrollvIEw第一层容器  private linearLayout ll_bottom_container;//底部容器  private VIEwPager vIEwPager;//滚动列表  private VIEwPager vIEwPager_2;  private MyVIEwPagerAdapter myVIEwPagerAdapter;//适配器  private List<String> image_urls;  private int y; //记住位移了多少  private boolean isRunAnimation = false;//判断当前动画是否执行完成  @OverrIDe  protected voID onCreate(Bundle savedInstanceState) {    super.onCreate(savedInstanceState);    setContentVIEw(R.layout.activity_main);    initVIEw();    initData();    initEvent();  }  private voID initVIEw() {    scrollVIEw = (ScrollVIEw) findVIEwByID(R.ID.scrollVIEw);    ll_container_scroll = (linearLayout) findVIEwByID(R.ID.ll_container_scroll);    ll_bottom_container = (linearLayout) findVIEwByID(R.ID.ll_bottom_container);    vIEwPager = (VIEwPager) findVIEwByID(R.ID.vIEwPager);    vIEwPager_2 = (VIEwPager) findVIEwByID(R.ID.vIEwPager_2);  }  private voID initData() {    image_urls = new ArrayList<>();    image_urls.add("http://pic31.nipic.com/20130624/8821914_104949466000_2.jpg");    image_urls.add("http://pic39.nipic.com/20140307/2531170_213037883000_2.jpg");    image_urls.add("http://pic10.nipic.com/20101020/3650425_202918301404_2.jpg");    image_urls.add("http://pic4.nipic.com/20091104/3178344_085047585414_2.jpg");    image_urls.add("http://pic4.nipic.com/20091101/3672704_160309066949_2.jpg");    myVIEwPagerAdapter = new MyVIEwPagerAdapter(this,image_urls);    vIEwPager.setAdapter(myVIEwPagerAdapter);    vIEwPager_2.setAdapter(myVIEwPagerAdapter);  }  private voID initEvent() {    //当前页的点击事件    myVIEwPagerAdapter.setonCurrentpositionClickListener(new MyVIEwPagerAdapter.OnCurrentVIEwClick() {      @OverrIDe      public voID onCurrentpositionClick(int position) {        if (vIEwPager.getTag() == null || ((Integer) vIEwPager.getTag()) == 1) {          showAnimation();        } else {          hIDeAnimation();        }      }    });    ll_bottom_container.setonClickListener(new VIEw.OnClickListener() {      @OverrIDe      public voID onClick(VIEw v) {        hIDeAnimation();      }    });  }  //显示动画  public voID showAnimation() {    if (!isRunAnimation) {      isRunAnimation = true;      int scrollY = scrollVIEw.getScrollY();      y = scrollY + ((ll_container_scroll.getMeasuredHeight() / 2) - (vIEwPager.getMeasuredHeight() / 2));      vIEwPager.animate()          .x(0f)          .y(y * 1f)          .setDuration(500)          .setListener(new Animator.AnimatorListener() {            @OverrIDe            public voID onAnimationStart(Animator animation) {              ll_bottom_container.setVisibility(VIEw.INVISIBLE);            }            @OverrIDe            public voID onAnimationEnd(Animator animation) {              isRunAnimation = false;              vIEwPager.setTag(2);              y = 0;              ll_container_scroll.setVisibility(VIEw.VISIBLE);              vIEwPager_2.setCurrentItem(vIEwPager.getCurrentItem(),false);            }            @OverrIDe            public voID onAnimationCancel(Animator animation) {            }            @OverrIDe            public voID onAnimationRepeat(Animator animation) {            }          });    }  }  //关闭动画  public voID hIDeAnimation() {    if (!isRunAnimation) {      vIEwPager.animate()          .x(0f)          .y(-y * 1f)          .setDuration(500)          .setListener(new Animator.AnimatorListener() {            @OverrIDe            public voID onAnimationStart(Animator animation) {              ll_container_scroll.setVisibility(VIEw.INVISIBLE);              vIEwPager.setCurrentItem(vIEwPager_2.getCurrentItem(),false);            }            @OverrIDe            public voID onAnimationEnd(Animator animation) {              isRunAnimation = false;              vIEwPager.setTag(1);              y = 0;              ll_bottom_container.setVisibility(VIEw.VISIBLE);            }            @OverrIDe            public voID onAnimationCancel(Animator animation) {            }            @OverrIDe            public voID onAnimationRepeat(Animator animation) {            }          });    }  }}

3、vIEwpager的适配器代码

package adapter;import androID.content.Context;import androID.net.Uri;import androID.support.v4.vIEw.PagerAdapter;import androID.vIEw.LayoutInflater;import androID.vIEw.VIEw;import androID.vIEw.VIEwGroup;import com.facebook.drawee.vIEw.SimpleDraweeVIEw;import com.newair.frescotextdemo.R;import java.util.List;/** * Created by ouhimehime on 16/4/28. * ---------VIEwPager适配器---------- */public class MyVIEwPagerAdapter extends PagerAdapter {  public interface OnCurrentVIEwClick {    voID onCurrentpositionClick(int position);  }  private OnCurrentVIEwClick onCurrentVIEwClick;  public voID setonCurrentpositionClickListener(OnCurrentVIEwClick onCurrentVIEwClick) {    this.onCurrentVIEwClick = onCurrentVIEwClick;  }  private Context context;  private List<String> myData;  public MyVIEwPagerAdapter(Context context,List<String> myData) {    this.context = context;    this.myData = myData;  }  @OverrIDe  public int getCount() {    return myData.size();  }  @OverrIDe  public boolean isVIEwFromObject(VIEw vIEw,Object object) {    return vIEw == object;  }  @OverrIDe  public Object instantiateItem(VIEwGroup container,final int position) {    SimpleDraweeVIEw simpleDraweeVIEw = (SimpleDraweeVIEw) LayoutInflater.from(context).inflate(R.layout.image_vIEw,null);    Uri uri = Uri.parse(myData.get(position));    simpleDraweeVIEw.setimageURI(uri);    container.addVIEw(simpleDraweeVIEw);    simpleDraweeVIEw.setonClickListener(new VIEw.OnClickListener() {      @OverrIDe      public voID onClick(VIEw v) {        onCurrentVIEwClick.onCurrentpositionClick(position);      }    });    return simpleDraweeVIEw;  }  @OverrIDe  public voID destroyItem(VIEwGroup container,int position,Object object) {    container.removeVIEw((SimpleDraweeVIEw) object);  }}

4、facebook的加载图片的控件

<?xml version="1.0" enCoding="utf-8"?><com.facebook.drawee.vIEw.SimpleDraweeVIEw xmlns:androID="http://schemas.androID.com/apk/res/androID"  xmlns:fresco="http://schemas.androID.com/apk/res-auto"  androID:layout_wIDth="match_parent"  androID:layout_height="match_parent"  fresco:actualimageScaleType="centerCrop"  fresco:fadeDuration="300"  fresco:placeholderImage="@mipmap/ic_launcher"></com.facebook.drawee.vIEw.SimpleDraweeVIEw>

还不是很好,感兴趣的可运行下看看。

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持编程小技巧。

总结

以上是内存溢出为你收集整理的Android仿一号店货物详情轮播图动画效果全部内容,希望文章能够帮你解决Android仿一号店货物详情轮播图动画效果所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1145967.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-31
下一篇 2022-05-31

发表评论

登录后才能评论

评论列表(0条)

保存