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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > Android >内容正文

Android

【Android实战】Gallary+ImageSwicther图片查看器

發布時間:2023/12/10 Android 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【Android实战】Gallary+ImageSwicther图片查看器 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

仿照如今各大新聞站點圖片新聞的瀏覽模式,上面展示詳細圖片(ImageSwitch),以下是能夠滑動的小圖片(Gallery)。

當中須要注意的是ImageSwitch須要定義一個工廠返回的組件,而且能夠設置動畫效果。

Gallery用適配器載入布局。其Gallery可設置。兩個圖片的間隔距離。

布局:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical" ><ImageSwitcherandroid:id="@+id/switcher"android:layout_width="fill_parent"android:layout_height="fill_parent"android:layout_gravity="center"android:layout_weight="1" ></ImageSwitcher><Galleryandroid:id="@+id/gallary"android:layout_width="fill_parent"android:layout_height="fill_parent"android:layout_margin="10dp"android:layout_weight="3"android:spacing="20dp" /></LinearLayout>
java類:

package com.gallaryandswitch;import android.app.Activity; import android.graphics.BitmapFactory; import android.os.Bundle; import android.view.View; import android.view.ViewGroup; import android.view.ViewGroup.LayoutParams; import android.view.animation.Animation; import android.view.animation.AnimationUtils;import android.widget.AdapterView; import android.widget.BaseAdapter; import android.widget.FrameLayout; import android.widget.Gallery; import android.widget.ImageSwitcher; import android.widget.ImageView; import android.widget.ImageView.ScaleType; import android.widget.LinearLayout; import android.widget.ViewSwitcher.ViewFactory;import com.example.wangyitest.R;public class MainAct extends Activity {ImageSwitcher imageSwitcher;Gallery gallery;int[] pics = { R.drawable.f1, R.drawable.f2, R.drawable.f3, R.drawable.f4,R.drawable.f5, R.drawable.f6, R.drawable.f7, R.drawable.flower };@Overrideprotected void onCreate(Bundle savedInstanceState) {// TODO Auto-generated method stubsuper.onCreate(savedInstanceState);setContentView(R.layout.galleryswitch);imageSwitcher = (ImageSwitcher) findViewById(R.id.switcher);gallery = (Gallery) findViewById(R.id.gallary);imageSwitcher.setFactory(new ViewFactory() {@Overridepublic View makeView() {// TODO Auto-generated method stubImageView imageView = new ImageView(getApplicationContext());imageView.setScaleType(ScaleType.FIT_CENTER);imageView.setLayoutParams(new FrameLayout.LayoutParams(FrameLayout.LayoutParams.FILL_PARENT,FrameLayout.LayoutParams.FILL_PARENT));imageView.setBackgroundColor(getResources().getColor(R.color.bg3));return imageView;}});imageSwitcher.setInAnimation(AnimationUtils.loadAnimation(getApplicationContext(), android.R.anim.fade_in));imageSwitcher.setOutAnimation(AnimationUtils.loadAnimation(getApplicationContext(), android.R.anim.fade_out));gallery.setAdapter(new MyAdapter());// gallery.setOnItemClickListener(new AdapterView.OnItemClickListener()// {//// @Override// public void onItemClick(AdapterView<?

> parent, View view, // int position, long id) { // // TODO Auto-generated method stub // imageSwitcher.setImageResource(pics[position]); // } // }); gallery.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { // TODO Auto-generated method stub imageSwitcher.setImageResource(pics[position]); } @Override public void onNothingSelected(AdapterView<?

> parent) { // TODO Auto-generated method stub } }); } class MyAdapter extends BaseAdapter { @Override public int getCount() { // TODO Auto-generated method stub return pics.length; } @Override public Object getItem(int position) { // TODO Auto-generated method stub 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) { // TODO Auto-generated method stub ImageView imageView = new ImageView(getApplicationContext()); imageView.setScaleType(ScaleType.FIT_CENTER); imageView.setLayoutParams(new Gallery.LayoutParams(400, Gallery.LayoutParams.WRAP_CONTENT)); imageView.setImageBitmap(BitmapFactory.decodeResource( getResources(), pics[position])); imageView.setBackgroundColor(getResources().getColor(R.color.bg2)); return imageView; } } }



轉載于:https://www.cnblogs.com/gcczhongduan/p/5306762.html

總結

以上是生活随笔為你收集整理的【Android实战】Gallary+ImageSwicther图片查看器的全部內容,希望文章能夠幫你解決所遇到的問題。

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