效果图:
项目结构:
在 https://blog.csdn.net/zhaihaohao1/article/details/100049893
的基础上,加入滑动大图切换画廊
ViewPager也能实现类似效果,所以放到ViewPager的分类中
代码如下:
activity_image_switcher.xml 中
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<ImageSwitcher
android:id="@+id/imageSwitcher"
android:layout_width="200dp"
android:layout_height="200dp"
android:scaleType="fitXY"
android:layout_gravity="center_horizontal"
/>
<!--spacing子控件之间的间距-->
<!--unselectedAlpha未选中子控件的透明度-->
<Gallery
android:id="@+id/gallery"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:spacing="10dp"
android:unselectedAlpha="0.5"
android:layout_marginTop="10dp"
/>
</LinearLayout>
ImageSwitcherActivity 中
package com.example.app2;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchLi