日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

图集

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

舉個栗子
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位技術專家共同創作,文字、視頻、音頻交互閱讀

總結

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

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