android gallery 画廊控件示例
16lz
2021-01-26
gallery.xml:
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="这是一个Gallery画廊控件的案例"/> <Gallery android:id="@+id/mygallery" android:layout_width="fill_parent" android:layout_height="fill_parent"/></LinearLayout>
GalleryActivity.java:
package com.example.baseexample;import android.app.Activity;import android.content.Context;import android.os.Bundle;import android.view.View;import android.view.ViewGroup;import android.widget.BaseAdapter;import android.widget.Gallery;import android.widget.ImageView;public class GalleryActivity extends Activity {private Gallery mGallery;public void onCreate(Bundle savedInstanceState){super.onCreate(savedInstanceState);setContentView(R.layout.gallery);mGallery = (Gallery)findViewById(R.id.mygallery);mGallery.setAdapter(new ImageAdapter(this));}private class ImageAdapter extends BaseAdapter{private Context mContext;private Integer[] mImage = {R.drawable.a,R.drawable.b,R.drawable.c,R.drawable.d,R.drawable.e,R.drawable.f};public ImageAdapter(Context c){mContext = c;}public int getCount(){return mImage.length;}public Object getItem(int position){return position;}public long getItemId(int position){return position;}public View getView(int position,View converView,ViewGroup parent){ImageView i = new ImageView(mContext);i.setImageResource(mImage[position]);i.setScaleType(ImageView.ScaleType.FIT_XY);i.setLayoutParams(new Gallery.LayoutParams(600, 1000));return i;}}}
更多相关文章
- 自定义Android侧滑菜单控件
- 过期Gallery取代方案horizontalscrollView之普通画廊
- 选择型控件
- android 获取控件宽度高度
- RadioGroup控件(接口类监听事件)
- Android重写ViewPager修改滑动灵敏度
- 安卓控件注入
- Android(安卓)圆形头像
- Android文字跑马灯