版權(quán)說(shuō)明:本文檔由用戶(hù)提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
【移動(dòng)應(yīng)用開(kāi)發(fā)技術(shù)】Android如何開(kāi)發(fā)仿微信發(fā)朋友圈瀏覽圖片效果
/upload/information/20201208/260/11099.jpg1.初始化數(shù)據(jù)源,設(shè)置適配器,看一下代碼:public
class
MyActivity
extends
Activity
{
/*圖片顯示列表*/
private
ListView
listView;
/*圖片URL數(shù)組*/
private
List<ContentBean>
contentBeans;
/*說(shuō)說(shuō)適配器*/
private
MyAdapter
adapter;
/**
*
Called
when
the
activity
is
first
created.
*/
@Override
public
void
onCreate(Bundle
savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
initData();
initViews();
}
/**
*
初始化數(shù)據(jù)
*/
private
void
initData(){
contentBeans
=
new
ArrayList<ContentBean>();
ArrayList<String>
imgUrls1
=
new
ArrayList<String>();
imgUrls1.add("http://7/110H2E40-6.jpg?attname=&e=1448288962&token=KDsCqUAWz3P-YT6In6oPnT56Eh3cig4zgQd12SJ_:AlTjfYD9SBFOdB4jmmZuKXAMOp8");
ContentBean
cb1
=
new
ContentBean(1,"java","Sun
Microsystems",imgUrls1);
contentBeans.add(cb1);
ArrayList<String>
imgUrls2
=
new
ArrayList<String>();
imgUrls2.add("http://7/110H2E40-6.jpg?attname=&e=1448288962&token=KDsCqUAWz3P-YT6In6oPnT56Eh3cig4zgQd12SJ_:AlTjfYD9SBFOdB4jmmZuKXAMOp8");
imgUrls2.add("http://7/110H2E40-6.jpg?attname=&e=1448288962&token=KDsCqUAWz3P-YT6In6oPnT56Eh3cig4zgQd12SJ_:AlTjfYD9SBFOdB4jmmZuKXAMOp8");
imgUrls2.add("http://7/110H2E40-6.jpg?attname=&e=1448288962&token=KDsCqUAWz3P-YT6In6oPnT56Eh3cig4zgQd12SJ_:AlTjfYD9SBFOdB4jmmZuKXAMOp8");
ContentBean
cb2
=
new
ContentBean(2,"OC","Stepstone",imgUrls2);
contentBeans.add(cb2);
ArrayList<String>
imgUrls3
=
new
ArrayList<String>();
imgUrls3.add("http://7/110H2E40-6.jpg?attname=&e=1448288962&token=KDsCqUAWz3P-YT6In6oPnT56Eh3cig4zgQd12SJ_:AlTjfYD9SBFOdB4jmmZuKXAMOp8");
imgUrls3.add("http://7/110H2E40-6.jpg?attname=&e=1448288962&token=KDsCqUAWz3P-YT6In6oPnT56Eh3cig4zgQd12SJ_:AlTjfYD9SBFOdB4jmmZuKXAMOp8");
imgUrls3.add("http://7/110H2E40-6.jpg?attname=&e=1448288962&token=KDsCqUAWz3P-YT6In6oPnT56Eh3cig4zgQd12SJ_:AlTjfYD9SBFOdB4jmmZuKXAMOp8");
imgUrls3.add("http://7/110H2E40-6.jpg?attname=&e=1448288962&token=KDsCqUAWz3P-YT6In6oPnT56Eh3cig4zgQd12SJ_:AlTjfYD9SBFOdB4jmmZuKXAMOp8");
imgUrls3.add("http://7/110H2E40-6.jpg?attname=&e=1448288962&token=KDsCqUAWz3P-YT6In6oPnT56Eh3cig4zgQd12SJ_:AlTjfYD9SBFOdB4jmmZuKXAMOp8");
imgUrls3.add("http://7/110H2E40-6.jpg?attname=&e=1448288962&token=KDsCqUAWz3P-YT6In6oPnT56Eh3cig4zgQd12SJ_:AlTjfYD9SBFOdB4jmmZuKXAMOp8");
imgUrls3.add("http://7/110H2E40-6.jpg?attname=&e=1448288962&token=KDsCqUAWz3P-YT6In6oPnT56Eh3cig4zgQd12SJ_:AlTjfYD9SBFOdB4jmmZuKXAMOp8");
imgUrls3.add("http://7/110H2E40-6.jpg?attname=&e=1448288962&token=KDsCqUAWz3P-YT6In6oPnT56Eh3cig4zgQd12SJ_:AlTjfYD9SBFOdB4jmmZuKXAMOp8");
imgUrls3.add("http://7/110H2E40-6.jpg?attname=&e=1448288962&token=KDsCqUAWz3P-YT6In6oPnT56Eh3cig4zgQd12SJ_:AlTjfYD9SBFOdB4jmmZuKXAMOp8");
ContentBean
cb3
=
new
ContentBean(3,"python","Guido
van
Rossum",imgUrls3);
contentBeans.add(cb3);
}
private
void
initViews(){
listView
=
(ListView)
findViewById(R.id.lv_my);
adapter
=
new
MyAdapter(MyActivity.this,contentBeans);
listView.setAdapter(adapter);
}
}public
class
MyAdapter
extends
BaseAdapter
{
private
Context
context;
private
List<ContentBean>
data;
public
MyAdapter(Context
context,
List<ContentBean>
data)
{
this.context
=
context;
this.data
=
data;
}
@Override
public
int
getCount()
{
return
data.size();
}
@Override
public
Object
getItem(int
i)
{
return
data.get(i);
}
@Override
public
long
getItemId(int
i)
{
return
i;
}
@Override
public
View
getView(int
i,
View
view,
ViewGroup
viewGroup)
{
ViewHolder
holder;
if
(view
==
null)
{
holder
=
new
ViewHolder();
view
=
View.inflate(context,
R.layout.item,
null);
holder.gridView
=
(NoScrollGridView)
view.findViewById(R.id.gridview);
holder.tvName
=
(TextView)
view.findViewById(R.id.tv_name);
holder.tvTitle
=
(TextView)
view.findViewById(R.id.tv_title);
view.setTag(holder);
}
else
{
holder
=
(ViewHolder)
view.getTag();
}
final
ContentBean
bean
=
data.get(i);
holder.tvName.setText(bean.getName());
holder.tvTitle.setText(bean.getTitle());
if
(data
!=
null
&&
data.size()
>
0)
{
holder.gridView.setAdapter(new
ImageGridAdapter(context,
bean.getImgUrls()));
}
/**
*
圖片列表點(diǎn)擊事件
*/
holder.gridView.setOnItemClickListener(new
AdapterView.OnItemClickListener()
{
@Override
public
void
onItemClick(AdapterView<?>
adapterView,
View
view,
int
i,
long
l)
{
Intent
intent
=
new
Intent(context,
ImagePagerActivity.class);
intent.putExtra(ImagePagerActivity.EXTRA_IMAGE_URLS,
(Serializable)
bean.getImgUrls());
intent.putExtra(ImagePagerActivity.EXTRA_IMAGE_INDEX,
i);
context.startActivity(intent);
}
});
return
view;
}
class
ViewHolder
{
TextView
tvName,
tvTitle;
NoScrollGridView
gridView;
}
}/**
*
圖片查看器
*/
public
class
ImagePagerActivity
extends
FragmentActivity
{
private
static
final
String
STATE_POSITION
=
"STATE_POSITION";
public
static
final
String
EXTRA_IMAGE_INDEX
=
"image_index";
public
static
final
String
EXTRA_IMAGE_URLS
=
"image_urls";
private
HackyViewPager
mPager;
private
int
pagerPosition;
private
TextView
indicator;
@Override
public
void
onCreate(Bundle
savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.image_detail_pager);
pagerPosition
=
getIntent().getIntExtra(EXTRA_IMAGE_INDEX,
0);
ArrayList<String>
urls
=
getIntent().getStringArrayListExtra(EXTRA_IMAGE_URLS);
mPager
=
(HackyViewPager)
findViewById(R.id.pager);
ImagePagerAdapter
mAdapter
=
new
ImagePagerAdapter(getSupportFragmentManager(),
urls);
mPager.setAdapter(mAdapter);
indicator
=
(TextView)
findViewById(R.id.indicator);
CharSequence
text
=
getString(R.string.viewpager_indicator,
1,
mPager.getAdapter().getCount());
indicator.setText(text);
//
更新下標(biāo)
mPager.setOnPageChangeListener(new
OnPageChangeListener()
{
@Override
public
void
onPageScrollStateChanged(int
arg0)
{
}
@Override
public
void
onPageScrolled(int
arg0,
float
arg1,
int
arg2)
{
}
@Override
public
void
onPageSelected(int
arg0)
{
CharSequence
text
=
getString(R.string.viewpager_indicator,
arg0
+
1,
mPager.getAdapter().getCount());
indicator.setText(text);
}
});
if
(savedInstanceState
!=
null)
{
pagerPosition
=
savedInstanceState.getInt(STATE_POSITION);
}
mPager.setCurrentItem(pagerPosition);
}
@Override
public
void
onSaveInstanceState(Bundle
outState)
{
outState.putInt(STATE_POSITION,
mPager.getCurrentItem());
}
private
class
ImagePagerAdapter
extends
FragmentStatePagerAdapter
{
public
ArrayList<String>
fileList;
public
ImagePagerAdapter(FragmentManager
fm,
ArrayList<String>
fileList)
{
super(fm);
this.fileList
=
fileList;
}
@Override
public
int
getCount()
{
return
fileList
==
null
?
0
:
fileList.size();
}
@Override
public
Fragment
getItem(int
position)
{
String
url
=
fileList.get(position);
return
ImageDetailFragment.newInstance(url);
}
}
}package
com.hankkin.WeiXinLookImgsDemo.activty;
import
android.graphics.Bitmap;
import
android.os.Bundle;
import
android.support.v4.app.Fragment;
import
android.view.LayoutInflater;
import
android.view.View;
import
android.view.ViewGroup;
import
android.widget.ImageView;
import
android.widget.ProgressBar;
import
android.widget.Toast;
import
com.hankkin.WeiXinLookImgsDemo.R;
import
com.nostra13.universalimageloader.core.ImageLoader;
import
com.nostra13.universalimageloader.core.assist.FailReason;
import
com.nostra13.universalimageloader.core.listener.SimpleImageLoadingListener;
import
com.others.PhotoViewAttacher;
/**
*
單張圖片顯示Fragment
*/
public
class
ImageDetailFragment
extends
Fragment
{
private
String
mImageUrl;
private
ImageView
mImageView;
private
ProgressBar
progressBar;
private
PhotoViewAttacher
mAttacher;
public
static
ImageDetailFragment
newInstance(String
imageUrl)
{
final
ImageDetailFragment
f
=
new
ImageDetailFragment();
final
Bundle
args
=
new
Bundle();
args.putString("url",
imageUrl);
f.setArguments(args);
return
f;
}
@Override
public
void
onCreate(Bundle
savedInstanceState)
{
super.onCreate(savedInstanceState);
mImageUrl
=
getArguments()
!=
null
?
getArguments().getString("url")
:
null;
}
@Override
public
View
onCreateView(LayoutInflater
inflater,
ViewGroup
container,
Bundle
savedInstanceState)
{
final
View
v
=
inflater.inflate(R.layout.image_detail_fragment,
container,
false);
mImageView
=
(ImageView)
v.findViewById(R.id.image);
mAttacher
=
new
PhotoViewAttacher(mImageView);
mAttacher.setOnPhotoTapListener(new
PhotoViewAttacher.OnPhotoTapListener()
{
@Override
public
void
onPhotoTap(View
arg0,
float
arg1,
float
arg2)
{
getActivity().finish();
}
});
mAttacher.setOnLongClickListener(new
View.OnLongClickListener()
{
@Override
public
boolean
onLongClick(View
view)
{
Toast.makeText(getActivity().getApplicationContext(),"保存",Toast.LENGTH_SHORT).show();
return
false;
}
});
progressBar
=
(ProgressBar)
v.findViewById(R.id.loading);
return
v;
}
@Override
public
void
onActivityCreated(Bundle
savedInstanceState)
{
super.onActivityCreated(savedInstanceState);
ImageLoader.getInstance().displayImage(mImageUrl,
mImageView,
new
SimpleImageLoadingListener()
{
@Override
public
void
onLoadingStarted(String
imageUri,
View
view)
{
progressBar.setVisibility(View.VISIBLE);
}
@Override
public
void
onLoadingFailed(String
imageUri,
View
view,
FailReason
failReason)
{
String
message
=
null;
switch
(failReason.getType())
{
case
IO_ERROR:
message
=
"下載錯(cuò)誤";
break;
case
DECODING_ERROR:
message
=
"圖片無(wú)法顯示";
break;
case
NETWORK_DENIED:
message
=
"網(wǎng)絡(luò)有問(wèn)題,無(wú)法下載";
break;
case
OUT_OF_MEMORY:
message
=
"圖片太大無(wú)法顯示";
break;
case
UNKNOWN:
message
=
"未知的錯(cuò)誤";
break;
}
Toast.makeText(getActivity(),
message,
Toast.LENGTH_SHORT).show();
progressBar.setVisibility(View.GONE);
}
@Override
public
void
onLoadingComplete(String
imageUri,
View
view,
Bitmap
loadedImage)
{
progressBar.setVisibility(View.GONE);
mAttacher.update();
}
});
}
}private
MyApplication
context;
@Override
public
void
onCreate()
{
super.onCreate();
context
=
this;
initImageLoader(context);
}
/**
*
初始化Imageloader
*
by
Hankkin
at:2015-11-22
23:20:29
*
@param
context
*/
public
static
void
initImageLoader(Context
context){
DisplayImageOptions
options
=
new
DisplayImageOptions.Builder()
.showImageOnLoading(R.drawable.ic_launcher)
.showImageOnFail(R.drawable.ic_launcher)
.resetViewBeforeLoading(false)
//
default
.delayBeforeLoading(0)
.cacheInMemory(true)
//
default
.cacheOnDisk(true)
//
default
.considerExifParams(true)
//
default
.imageScaleType(ImageScaleType.IN_SAMPLE_POWER_OF_2)
//
default
.bitmapConfig(Bitmap.Config.ARGB_8888)
//
default
.displayer(new
SimpleBitmapDisplayer())
//
default
.handler(new
Handler())
//
default
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶(hù)所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶(hù)上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶(hù)上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶(hù)因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 直郵廣告解決方案
- 二零二五年度房產(chǎn)租賃合同終止催告通知3篇
- 二零二五年度房地產(chǎn)物業(yè)管理合同范本5篇
- “銀色數(shù)字鴻溝”對(duì)老年人身心健康的影響
- “雙減”背景下學(xué)校課后服務(wù)質(zhì)量的問(wèn)題、原因及策略
- 蜜雪冰城企業(yè)案例分析
- 四川省瀘州市龍馬潭區(qū)瀘化中學(xué)2024-2025學(xué)年九年級(jí)上學(xué)期1月期末考試化學(xué)試卷(含答案)
- 建設(shè)生物質(zhì)加工利用及年產(chǎn)3萬(wàn)噸炭素資源化利用項(xiàng)目可行性研究報(bào)告模板-立項(xiàng)拿地
- 福建省廈門(mén)市同安區(qū)2024-2025學(xué)年八年級(jí)上學(xué)期期末模擬語(yǔ)文試卷(含答案)
- Unit5 Humans and nature Lesson 3 Race to the pole 說(shuō)課稿 -2024-2025學(xué)年高中英語(yǔ)北師大版(2019)必修第二冊(cè)
- 監(jiān)理人員安全生產(chǎn)培訓(xùn)
- 2024-2030年中國(guó)電力檢修行業(yè)運(yùn)行狀況及投資前景趨勢(shì)分析報(bào)告
- 河北省百師聯(lián)盟2023-2024學(xué)年高二上學(xué)期期末大聯(lián)考?xì)v史試題(解析版)
- 中央空調(diào)系統(tǒng)運(yùn)行與管理考核試卷
- 核電工程排水隧道專(zhuān)項(xiàng)施工方案
- 2024年市場(chǎng)運(yùn)營(yíng)部職責(zé)樣本(3篇)
- 民辦學(xué)校招生教師培訓(xùn)
- 煉鐵行業(yè)的安全生產(chǎn)與環(huán)境保護(hù)考核試卷
- 抗菌藥物的合理應(yīng)用培訓(xùn)
- 初三數(shù)學(xué)老師家長(zhǎng)會(huì)發(fā)言稿
- 能源崗位招聘筆試題及解答(某大型央企)
評(píng)論
0/150
提交評(píng)論