ImageSwitcher GridView BaseAdapter 实现图库案例 源码
首先看效果图吧
首先准备GridView进行所有图片的列表显示
布局代码
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout 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" > <GridView android:id="@+id/gridView1" android:layout_width="match_parent" android:layout_height="wrap_content" android:numColumns="3" android:columnWidth="90dp" android:horizontalSpacing="10dp" android:verticalSpacing="10dp" android:stretchMode="columnWidth"/> </RelativeLayout>
java代码
public class GalleryActivity extends AppCompatActivity { private GridView gridView; private ImageGridViewAdapter adapter; private ArrayList<Integer> data; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_gallery); gridView=findViewById(R.id.gridView1