It's not very complete yet. At present, you can only click the middle picture to move, and there are no other areas outside the picture. . (Attribute animation), by the way, the picture loading is used as a Facebook and Android picture loading library. It feels very NB, and it's all the best.
1. Look at the layout first
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:andro xmlns:tools="/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity"> <ScrollView android: 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: android:layout_width="match_parent" android:layout_height="300dp" /> <LinearLayout android: 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> <!-- Auxiliary function,Used to calculate the middle position of the screen --> <LinearLayout android: android:layout_width="match_parent" android:layout_height="match_parent" android:background="#bfbfbf" android:gravity="center" android:orientation="horizontal" android:visibility="invisible"> <!-- Must be shown aboveviewpagerJust as tall --> <. android: android:layout_width="match_parent" android:layout_height="300dp" /> </LinearLayout> </RelativeLayout>
2. Main interface code
package ; import ; import .; import .; import ; import ; import ; import ; import ; import ; import ; import ; import ; public class MainActivity extends AppCompatActivity { private ScrollView scrollView; private LinearLayout ll_container_scroll;//scrollview first layer container private LinearLayout ll_bottom_container;//Bottom container private ViewPager viewPager;//Scroll the list private ViewPager viewPager_2; private MyViewPagerAdapter myViewPagerAdapter;//adapter private List<String> image_urls; private int y; //Remember how much displacement has been private boolean isRunAnimation = false;//Discern whether the current animation is completed @Override protected void onCreate(Bundle savedInstanceState) { (savedInstanceState); setContentView(.activity_main); initView(); initData(); initEvent(); } private void initView() { scrollView = (ScrollView) findViewById(); ll_container_scroll = (LinearLayout) findViewById(.ll_container_scroll); ll_bottom_container = (LinearLayout) findViewById(.ll_bottom_container); viewPager = (ViewPager) findViewById(); viewPager_2 = (ViewPager) findViewById(.viewPager_2); } private void initData() { image_urls = new ArrayList<>(); image_urls.add("/20130624/8821914_104949466000_2.jpg"); image_urls.add("/20140307/2531170_213037883000_2.jpg"); image_urls.add("/20101020/3650425_202918301404_2.jpg"); image_urls.add("/20091104/3178344_085047585414_2.jpg"); image_urls.add("/20091101/3672704_160309066949_2.jpg"); myViewPagerAdapter = new MyViewPagerAdapter(this, image_urls); (myViewPagerAdapter); viewPager_2.setAdapter(myViewPagerAdapter); } private void initEvent() { //Click event on the current page (new () { @Override public void onCurrentPositionClick(int position) { if (() == null || ((Integer) ()) == 1) { showAnimation(); } else { hideAnimation(); } } }); ll_bottom_container.setOnClickListener(new () { @Override public void onClick(View v) { hideAnimation(); } }); } //Show animation public void showAnimation() { if (!isRunAnimation) { isRunAnimation = true; int scrollY = (); y = scrollY + ((ll_container_scroll.getMeasuredHeight() / 2) - (() / 2)); () .x(0f) .y(y * 1f) .setDuration(500) .setListener(new () { @Override public void onAnimationStart(Animator animation) { ll_bottom_container.setVisibility(); } @Override public void onAnimationEnd(Animator animation) { isRunAnimation = false; (2); y = 0; ll_container_scroll.setVisibility(); viewPager_2.setCurrentItem((),false); } @Override public void onAnimationCancel(Animator animation) { } @Override public void onAnimationRepeat(Animator animation) { } }); } } //Close the animation public void hideAnimation() { if (!isRunAnimation) { () .x(0f) .y(-y * 1f) .setDuration(500) .setListener(new () { @Override public void onAnimationStart(Animator animation) { ll_container_scroll.setVisibility(); (viewPager_2.getCurrentItem(),false); } @Override public void onAnimationEnd(Animator animation) { isRunAnimation = false; (1); y = 0; ll_bottom_container.setVisibility(); } @Override public void onAnimationCancel(Animator animation) { } @Override public void onAnimationRepeat(Animator animation) { } }); } } }
3. Viewpager adapter code
package adapter; import ; import ; import .; import ; import ; import ; import ; import ; import ; /** * Created by ouhimehime on 16/4/28. * ---------ViewPager adapter ----------- */ public class MyViewPagerAdapter extends PagerAdapter { public interface OnCurrentViewClick { void onCurrentPositionClick(int position); } private OnCurrentViewClick onCurrentViewClick; public void setOnCurrentPositionClickListener(OnCurrentViewClick onCurrentViewClick) { = onCurrentViewClick; } private Context context; private List<String> myData; public MyViewPagerAdapter(Context context, List<String> myData) { = context; = myData; } @Override public int getCount() { return (); } @Override public boolean isViewFromObject(View view, Object object) { return view == object; } @Override public Object instantiateItem(ViewGroup container, final int position) { SimpleDraweeView simpleDraweeView = (SimpleDraweeView) (context).inflate(.image_view, null); Uri uri = ((position)); (uri); (simpleDraweeView); (new () { @Override public void onClick(View v) { (position); } }); return simpleDraweeView; } @Override public void destroyItem(ViewGroup container, int position, Object object) { ((SimpleDraweeView) object); } }
4. Facebook's controls for loading pictures
<?xml version="1.0" encoding="utf-8"?> < xmlns:andro xmlns:fresco="/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" fresco:actualImageScaleType="centerCrop" fresco:fadeDuration="300" fresco:placeholderImage="@mipmap/ic_launcher"> </>
Not very good yet, if you are interested, you can run it.
The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.