第六篇 Gallery与ImageSwitcher混合使用
16lz
2021-01-24
直奔主题~!
结构如图:
main.xml代码:
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:orientation="vertical" android:layout_width="fill_parent"android:layout_height="fill_parent" android:gravity="center"><ImageSwitcher android:id="@+id/is"android:layout_width="300dip" android:layout_height="300dip"></ImageSwitcher><Gallery android:layout_width="fill_parent" android:id="@+id/gl"android:layout_height="wrap_content" android:spacing="5dip"></Gallery></LinearLayout>
Control_Gallery_ImageSwitcher .java代码:
public class Control_Gallery_ImageSwitcherActivity extends Activity {private ImageSwitcher is;private Gallery gl;int[] imggroup; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); findAll(); bind(); } public void findAll() { is=(ImageSwitcher) this.findViewById(R.id.is); gl=(Gallery) this.findViewById(R.id.gl); imggroup=new int[]{R.raw.jwc1,R.raw.jwc2,R.raw.jwc3,R.raw.jwc4,R.raw.jwc5}; } public void bind() { is.setFactory(new ViewFactory() {public View makeView() {// TODO Auto-generated method stub//return null;ImageView iv=new ImageView(Control_Gallery_ImageSwitcherActivity.this);iv.setLayoutParams(new ImageSwitcher.LayoutParams(100, 100));return iv;}}); is.setAnimation(AnimationUtils.loadAnimation(Control_Gallery_ImageSwitcherActivity.this, android.R.anim.fade_in)); is.setAnimation(AnimationUtils.loadAnimation(Control_Gallery_ImageSwitcherActivity.this, android.R.anim.fade_out)); is.setBackgroundResource(imggroup[0]); gl.setAdapter(new myadpter(Control_Gallery_ImageSwitcherActivity.this)); gl.setOnItemClickListener(new OnItemClickListener() {public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,long arg3) {// TODO Auto-generated method stubis.setBackgroundResource(imggroup[arg2]);}}); } class myadpter extends BaseAdapter { Context ct; public myadpter(Context ct) { this.ct=ct; }public int getCount() {// TODO Auto-generated method stubreturn imggroup.length;}public Object getItem(int position) {// TODO Auto-generated method stubreturn position;}public long getItemId(int position) {// TODO Auto-generated method stubreturn position;}public View getView(int position, View convertView, ViewGroup parent) {// TODO Auto-generated method stub//return null; ImageView iv=new ImageView(ct); iv.setImageBitmap(BitmapFactory.decodeResource(getResources(), imggroup[position])) ; iv.setLayoutParams(new Gallery.LayoutParams(80, 80));return iv;} }}
更多相关文章
- Android中一种ThreadPool的实现
- 带图片的按钮-Android源代码
- zxin android客户端二维码框问题
- Android之定义各种样式的标题栏
- android模拟器分辨率设置以及获得模拟器分辨率代码片段
- android实现接通和挂断电话
- 【高通SDM660平台 Android(安卓)10.0】(11) --- Eeprom lib 与 K
- Android.mk 代码注释
- Android开发常用经典代码段集锦
随机推荐
- HTML5 Cache, Android(安卓)WebView
- Android(安卓)动态获取资源ID
- Android(安卓)- ImageView 加边框 实例
- Android(安卓)InputMethodManager泄漏Act
- android中的定时任务AlarmManager
- Android(安卓)Splash Activity Demo
- android listview 调用sqlsite数据库显示
- Android(安卓)drivers to be included in
- Android(安卓)Out of Memory Error: Caus
- Android(安卓)播放音乐文件与视频文