Android Gallery 画廊Demo
16lz
2021-01-23
Android Gallery 画廊Demo
源代码:http://yuncode.net/code/c_5039963a841a379
- publicclassSampleextendsActivity{
- int[]imageIDs={
- R.drawable.bbta,R.drawable.bbtb,R.drawable.bbtc,
- R.drawable.bbtd,R.drawable.bbte,R.drawable.bbtf,
- R.drawable.bbtg
- };
- @Override
- publicvoidonCreate(BundlesavedInstanceState){
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- Gallerygl=(Gallery)this.findViewById(R.id.Gallery01);
- BaseAdapterba=newBaseAdapter(){
- @Override
- publicintgetCount(){
- returnimageIDs.length;
- }
- @Override
- publicObjectgetItem(intarg0){
- returnnull;
- }
- @Override
- publiclonggetItemId(intarg0){
- return0;
- }
- @Override
- publicViewgetView(intarg0,Viewarg1,ViewGrouparg2){
- ImageViewiv=newImageView(Sample_5_8.this);
- iv.setImageResource(imageIDs[arg0]);
- iv.setScaleType(ImageView.ScaleType.FIT_XY);
- iv.setLayoutParams(newGallery.LayoutParams(188,250));
- returniv;
- }
- };
- gl.setAdapter(ba);
- gl.setOnItemClickListener(
- newOnItemClickListener(){
- @Override
- publicvoidonItemClick(AdapterView<?>arg0,Viewarg1,
- intarg2,longarg3){
- Gallerygl=(Gallery)findViewById(R.id.Gallery01);
- gl.setSelection(arg2);
- }
- }
- );
- }
- }
- <?xmlversion="1.0"encoding="utf-8"?>
- <LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="vertical"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:gravity="center_vertical"
- >
- <Gallery
- android:id="@+id/Gallery01"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:spacing="10dip"
- android:unselectedAlpha="1"/>
- </LinearLayout>
更多相关文章
- CentOS 下载 Android 源代码。
- android 下载不了源代码?
- Android下MP3播放器的实现源代码02
- Android下MP3播放器的实现源代码03
- 转:在Eclipse中查看Android SDK的源代码
- android源代码分布结构
- Android系统手机重启与恢复出产设置源代码跟踪