日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

图集

發布時間:2025/4/16 编程问答 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 图集 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

舉個栗子
xml

<ImageSwitcher android:id="@+id/imageSwitcher"android:layout_width="match_parent"android:layout_height="wrap_content"android:layout_weight="1"android:layout_centerInParent="true" /><Gallery android:id="@+id/gallery" android:background="#55000000"android:layout_width="fill_parent" android:layout_height="wrap_content"android:layout_alignParentBottom="true" android:spacing="0dp" />復制代碼

java

public class xx extends Activity { // 顯示圖片的資源 private static int[] images = {R.mipmap.wallpaper_x, xx}; Gallery gallery; ImageSwitcher is; @Override protected void onCreate(Bundle savedInstanceState) {// TODO Auto-generated method stubsuper.onCreate(savedInstanceState);setContentView(R.layout.xx);gallery = (Gallery) findViewById(R.id.gallery);is = (ImageSwitcher) findViewById(R.id.imageSwitcher);gallery.setAdapter(new ImageAdapter(this));// 讓選定的圖片在中心顯示gallery.setSelection(images.length / 2);// 為Gallery綁定監聽器;gallery.setOnItemSelectedListener(new OnItemSelectedListener() {public void onItemSelected(AdapterView<?> parent, View view,int position, long id) {// 當在Gallery中選定一張圖片是 ImageSwitcher同步顯示同一張// position%images.length 為了讓圖片循環顯示is.setImageResource(images[position % images.length]);}public void onNothingSelected(AdapterView<?> parent) {}});is.setFactory(new ImageFactory(this));}private class ImageAdapter extends BaseAdapter {private Context context;public ImageAdapter(Context context) {this.context = context;}// 可以return images.lenght(),在這里返回Integer.MAX_VALUE// 是為了使圖片循環顯示public int getCount() {return images.length;}public Object getItem(int position) {return null;}public long getItemId(int position) {return 0;}public View getView(int position, View convertView, ViewGroup parent) {ImageView iv = new ImageView(context);iv.setScaleType(ImageView.ScaleType.CENTER_CROP);iv.setImageResource(images[position % images.length]);iv.setLayoutParams(new Gallery.LayoutParams(250, 350));iv.setAdjustViewBounds(true);return iv;} }private class ImageFactory implements ViewFactory {private Context context;public ImageFactory(Context context) {this.context = context;}public View makeView() {ImageView iv = new ImageView(context);iv.setLayoutParams(new ImageSwitcher.LayoutParams(-1, -1));return iv;} }復制代碼

}

《新程序員》:云原生和全面數字化實踐50位技術專家共同創作,文字、視頻、音頻交互閱讀

總結

以上是生活随笔為你收集整理的图集的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。