首页 > 代码库 > 王立平--Gallery:实现图片的左右滑动
王立平--Gallery:实现图片的左右滑动
<span style="font-size:18px;color:#330033;">package com.main; 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; @SuppressWarnings("deprecation") public class MainActivity extends Activity { Gallery gallery; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); gallery = (Gallery)findViewById(R.id.gallery); gallery.setAdapter(new ImageAdapter(this)); gallery.pointToPosition(0, 0); } class ImageAdapter extends BaseAdapter{ private Context context; //图片源数组 private Integer[] imageInteger={ R.drawable.ic_launcher, R.drawable.bg3, R.drawable.ic_launcher, R.drawable.bg3, R.drawable.ic_launcher, R.drawable.bg3, R.drawable.ic_launcher, R.drawable.bg3 }; public ImageAdapter(Context c){ context = c; } @Override public int getCount() { return imageInteger.length; } @Override public Object getItem(int position) { return position; } @Override public long getItemId(int position) { // TODO Auto-generated method stub return position; } @Override public View getView(int position, View convertView, ViewGroup parent) { ImageView imageView = new ImageView(context); imageView.setImageResource(imageInteger[position]); imageView.setScaleType(ImageView.ScaleType.FIT_XY); return imageView; }} }</span>-----------------------------------------------------------------------------------------
<span style="font-size:18px;color:#330033;"><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="fill_parent" android:layout_height="fill_parent" > <Gallery android:id="@+id/gallery" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_alignParentTop="true" android:gravity="fill_vertical" android:spacing="10dp" android:background="#0000FF" android:padding="0dp" /> </RelativeLayout> </span>
王立平--Gallery:实现图片的左右滑动
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。