使用ImageSwitcher和Gallery实现图片的浏览
来源:互联网 发布:对口型软件 编辑:程序博客网 时间:2024/04/30 07:26
<pre class="html" name="code"><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context=".MainActivity" > <LinearLayout android:layout_width="fill_parent" android:layout_height="250dp" android:gravity="center"> <ImageSwitcher android:id="@+id/IS01" android:layout_width="wrap_content" android:layout_height="wrap_content" > </ImageSwitcher> </LinearLayout> <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <Gallery android:id="@+id/Ga01" android:layout_width="fill_parent" android:layout_height="80dp" android:spacing="5dp"/> </LinearLayout></LinearLayout>
package cn.edu.bzu.mageswitcher;import cn.edu.bzu.mageswitcher.R;import android.os.Bundle;import android.app.Activity;import android.content.Context;import android.view.Menu;import android.view.View;import android.view.ViewGroup;import android.widget.AdapterView;import android.widget.AdapterView.OnItemClickListener;import android.widget.BaseAdapter;import android.widget.Gallery;import android.widget.ImageSwitcher;import android.widget.ImageView;import android.widget.ViewSwitcher.ViewFactory;public class MainActivity extends Activity implements ViewFactory {private final static Integer[] INTEGERS = {R.drawable.a,R.drawable.b,R.drawable.c,R.drawable.d,R.drawable.e,R.drawable.f,R.drawable.g,R.drawable.h,};ImageSwitcher imageSwitcher;Gallery gallery;private static int index=0;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);imageSwitcher = (ImageSwitcher)findViewById(R.id.IS01);imageSwitcher.setFactory(this);imageSwitcher.setImageResource(INTEGERS[index]);gallery = (Gallery)findViewById(R.id.Ga01);gallery.setAdapter(new ImageAdapter(this));gallery.setOnItemClickListener(new OnItemClickListener() {@Overridepublic void onItemClick(AdapterView<?> arg0, View arg1, int position,long arg3) {imageSwitcher.setImageResource(INTEGERS[position]);}});}@Overridepublic boolean onCreateOptionsMenu(Menu menu) {// Inflate the menu; this adds items to the action bar if it is present.getMenuInflater().inflate(R.menu.main, menu);return true;}@Overridepublic View makeView() {return new ImageView(this);}class ImageAdapter extends BaseAdapter{Context context;public ImageAdapter(Context context){this.context = context;}@Overridepublic int getCount() {// TODO Auto-generated method stubreturn INTEGERS.length;}@Overridepublic Object getItem(int position) {// TODO Auto-generated method stubreturn position;}@Overridepublic long getItemId(int position) {// TODO Auto-generated method stubreturn position;}@Overridepublic View getView(int position, View v, ViewGroup vg) {ImageView imageView = new ImageView(context);imageView.setImageResource(INTEGERS[position]);imageView.setLayoutParams(new Gallery.LayoutParams(120, 120));imageView.setScaleType(ImageView.ScaleType.FIT_CENTER);return imageView;}}}
0 0
- 使用ImageSwitcher和Gallery实现图片的浏览
- 使用ImageSwitcher和Gallery实现图片的浏览
- ImageSwitcher与gallery图片浏览
- Gallery和imageSwitcher结合使用浏览图片(简单图片浏览器)
- ImageSwitcher 和 Gallery 的使用
- ImageSwitcher和Gallery的使用
- android 用ImageSwitcher+Gallery实现图片浏览效果
- 简单图片浏览工具—ImageSwitcher和Gallery组件结合使用
- 使用Gallery和ImageSwitcher制作图片浏览器
- Eg:Gallery与ImageSwitcher结合的图片浏览小程序
- Android ImageSwitcher 和 Gallery 浏览图片时 OutofMemory问题的解决
- 使用ImageSwitcher和Gallery实现左右滑动
- 使用ImageSwitcher和Gallery实现左右滑动
- Android中Gallery和ImageSwitcher的使用
- Android中Gallery和ImageSwitcher的使用
- ImageSwitcher gallery 实现图片展示
- 【Android基础知识】使用Gallery和ImageSwitcher实现图片轮播效果
- 简单图片浏览器(ImageSwitcher和Gallery结合使用)
- LeetCode: Binary Tree Preorder Traversal [144]
- Oracle 创建create user 及授权grant
- 主动FTP和被动FTP
- POJ 2478 Farey Sequence
- [Android记录]meta-data小结
- 使用ImageSwitcher和Gallery实现图片的浏览
- LeetCode: Single Number II
- uva 10623 - Thinking Backward(数学)
- LeetCode: Binary Tree Postorder Traversal [145]
- 关闭系统声音也可以播放出声音
- LeetCode: LRU Cache [146]
- 【笔记】my socket code
- 设计模式在cocos2d-x中的使用--简单工厂模式(Simple Factory)
- MATLAB中的柱面与球面