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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

android 广告栏效果,实现android广告栏效果

發布時間:2025/3/8 编程问答 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 android 广告栏效果,实现android广告栏效果 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

public classBannerLayout extendsRelativeLayout {

privateViewPager mViewPager; // 輪播容器// 指示器(圓點)容器privateLinearLayout indicatorContainer;

privateDrawable unSelectedDrawable;

privateDrawable selectedDrawable;

private intWHAT_AUTO_PLAY= 1000;

private booleanisAutoPlay= true; // 自動輪播private intitemCount;

private intselectedIndicatorColor= 0xffff0000;

private intunSelectedIndicatorColor= 0x88888888;

private inttitleBGColor= 0X33000000;

private inttitleColor= 0Xffffffff;

privateShape indicatorShape= Shape.oval;

private intselectedIndicatorHeight= 20;

private intselectedIndecatorWidth= 20;

private intunSelectedIndicatorHeight= 20;

private intunSelectedIndecatorWidth= 20;

private intautoPlayDuration= 4000;

private intscrollDuration= 900;

// 指示器中點和點之間的距離private intindicatorSpace= 15;

// 指示器整體的設置private intindicatorMargin= 20;

private static final inttitlePadding= 20;

private intdefaultImage;

private enumShape {

// 矩形 或 圓形的指示器rect, oval}

privateOnBannerItemClickListener mOnBannerItemClickListener;

privateHandler mHandler= newHandler(newHandler.Callback() {

@Overridepublic booleanhandleMessage(Message msg) {

if(msg.what== WHAT_AUTO_PLAY) {

if(mViewPager!= null) {

mViewPager.setCurrentItem(mViewPager.getCurrentItem() + 1, true);

mHandler.sendEmptyMessageDelayed(WHAT_AUTO_PLAY, autoPlayDuration);

}

}

return false;

}

});

publicBannerLayout(Context context) {

super(context);

init(null, 0);

}

publicBannerLayout(Context context, AttributeSet attrs) {

super(context, attrs);

init(attrs, 0);

}

publicBannerLayout(Context context, AttributeSet attrs, intdefStyleAttr) {

super(context, attrs, defStyleAttr);

init(attrs, defStyleAttr);

}

private voidinit(AttributeSet attrs, intdefStyleAttr) {

TypedArray array = getContext().obtainStyledAttributes(attrs, R.styleable.BannerLayoutStyle, defStyleAttr, 0);

selectedIndicatorColor= array.getColor(R.styleable.BannerLayoutStyle_selectedIndicatorColor, selectedIndicatorColor);

unSelectedIndicatorColor= array.getColor(R.styleable.BannerLayoutStyle_unSelectedIndicatorColor, unSelectedIndicatorColor);

titleBGColor= array.getColor(R.styleable.BannerLayoutStyle_titleBGColor, titleBGColor);

titleColor= array.getColor(R.styleable.BannerLayoutStyle_titleColor, titleColor);

intshape = array.getInt(R.styleable.BannerLayoutStyle_indicatorShape, Shape.oval.ordinal());

for(Shape shape1 : Shape.values()) {

if(shape1.ordinal() == shape) {

indicatorShape= shape1;

break;

}

}

selectedIndecatorWidth= (int) array.getDimension(R.styleable.BannerLayoutStyle_selectedIndicatorWidth, selectedIndecatorWidth);

selectedIndicatorHeight= (int) array.getDimension(R.styleable.BannerLayoutStyle_selectedIndicatorHeight, selectedIndicatorHeight);

unSelectedIndecatorWidth= (int) array.getDimension(R.styleable.BannerLayoutStyle_unSelectedIndicatorWidth, unSelectedIndecatorWidth);

unSelectedIndicatorHeight= (int) array.getDimension(R.styleable.BannerLayoutStyle_unSelectedIndicatorHeight, unSelectedIndicatorHeight);

indicatorSpace= (int) array.getDimension(R.styleable.BannerLayoutStyle_indicatorSpace, indicatorSpace);

indicatorMargin= (int) array.getDimension(R.styleable.BannerLayoutStyle_indicatorMargin, indicatorMargin);

autoPlayDuration= array.getInt(R.styleable.BannerLayoutStyle_autoPlayDuration, autoPlayDuration);

scrollDuration= array.getInt(R.styleable.BannerLayoutStyle_scrollDuration, scrollDuration);

isAutoPlay= array.getBoolean(R.styleable.BannerLayoutStyle_isAutoPlay, isAutoPlay);

defaultImage= array.getResourceId(R.styleable.BannerLayoutStyle_defaultImage, defaultImage);

array.recycle();

LayerDrawable unSelectedLayerDrawable;

LayerDrawable selectedLayerDrawable;

GradientDrawable unSelectedGradientDrawable = newGradientDrawable();

GradientDrawable selectedGradientDtawbale = newGradientDrawable();

switch(indicatorShape) {

caserect:

unSelectedGradientDrawable.setShape(GradientDrawable.RECTANGLE);

selectedGradientDtawbale.setShape(GradientDrawable.RECTANGLE);

break;

caseoval:

unSelectedGradientDrawable.setShape(GradientDrawable.OVAL);

selectedGradientDtawbale.setShape(GradientDrawable.OVAL);

break;

}

unSelectedGradientDrawable.setColor(unSelectedIndicatorColor);

unSelectedGradientDrawable.setSize(unSelectedIndecatorWidth, unSelectedIndicatorHeight);

unSelectedLayerDrawable = newLayerDrawable(newDrawable[]{unSelectedGradientDrawable});

unSelectedDrawable= unSelectedLayerDrawable;

selectedGradientDtawbale.setColor(selectedIndicatorColor);

selectedGradientDtawbale.setSize(selectedIndecatorWidth, selectedIndicatorHeight);

selectedLayerDrawable = newLayerDrawable(newDrawable[]{selectedGradientDtawbale});

selectedDrawable= selectedLayerDrawable;

}

/*** 添加本地圖片**@paramviewRes圖片id集合*@paramtitles標題集合,可空*/public voidsetViewRes(List viewRes, List titles) {

List views = newArrayList<>();

itemCount= viewRes.size();

if(titles != null&& titles.size() != viewRes.size()) {

throw newIllegalStateException("views.size() != titles.size()");

}

// 把數量拼湊到三個以上if(itemCount< 1) {

throw newIllegalStateException("item count not equal zero");

} else if(itemCount< 2) {

views.add(getFrameLayoutView(viewRes.get(0), titles != null? titles.get(0) : null, 0));

views.add(getFrameLayoutView(viewRes.get(0), titles != null? titles.get(0) : null, 0));

views.add(getFrameLayoutView(viewRes.get(0), titles != null? titles.get(0) : null, 0));

} else if(itemCount< 3) {

views.add(getFrameLayoutView(viewRes.get(0), titles != null? titles.get(0) : null, 0));

views.add(getFrameLayoutView(viewRes.get(1), titles != null? titles.get(1) : null, 1));

views.add(getFrameLayoutView(viewRes.get(0), titles != null? titles.get(0) : null, 0));

views.add(getFrameLayoutView(viewRes.get(1), titles != null? titles.get(1) : null, 1));

} else{

for(inti = 0; i < viewRes.size(); i++) {

views.add(getFrameLayoutView(viewRes.get(i), titles != null? titles.get(i) : null, i));

}

}

setViews(views);

}

//添加網絡圖片路徑public voidsetViewUrls(Context context,List urls, List titles) {

List views = newArrayList<>();

itemCount= urls.size();

Log.e("TAG",titles.size()+"---90---"+urls.size());

if(titles != null&& titles.size() != itemCount) {

throw newIllegalStateException("views.size() != titles.size()");

}

//主要是解決當item為小于3個的時候滑動有問題,這里將其拼湊成3個以上if(itemCount< 1) {//當item個數0throw newIllegalStateException("item count not equal zero");

} else if(itemCount< 2) { //當item個數為1views.add(getFrameLayoutView(context,urls.get(0), titles != null? titles.get(0) : null, 0));

views.add(getFrameLayoutView(context,urls.get(0), titles != null? titles.get(0) : null, 0));

views.add(getFrameLayoutView(context,urls.get(0), titles != null? titles.get(0) : null, 0));

} else if(itemCount< 3) {//當item個數為2views.add(getFrameLayoutView(context,urls.get(0), titles != null? titles.get(0) : null, 0));

views.add(getFrameLayoutView(context,urls.get(1), titles != null? titles.get(1) : null, 1));

views.add(getFrameLayoutView(context,urls.get(0), titles != null? titles.get(0) : null, 0));

views.add(getFrameLayoutView(context,urls.get(1), titles != null? titles.get(1) : null, 1));

} else{

for(inti = 0; i < urls.size(); i++) {

views.add(getFrameLayoutView(context,urls.get(i), titles != null? titles.get(i) : null, i));

}

}

setViews(views);

}

private voidsetViews(finalList views) {

mViewPager= newViewPager(getContext());

addView(mViewPager);

setSliderTransformDuration(scrollDuration);

//初始化indicatorContainerindicatorContainer= newLinearLayout(getContext());

indicatorContainer.setGravity(Gravity.CENTER_VERTICAL);

LayoutParams params = newLayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);

// 設置 指示點的位置 ALIGN_PARENT_RIGHT表示居右 CENTER_HORIZONTAL表示居中params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);

params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);

//設置marginparams.setMargins(indicatorMargin, indicatorMargin, indicatorMargin, indicatorMargin);

//添加指示器容器布局到SliderLayoutaddView(indicatorContainer, params);

//初始化指示器,并添加到指示器容器布局for(inti = 0; i < itemCount; i++) {

ImageView indicator = newImageView(getContext());

indicator.setLayoutParams(newViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));

indicator.setPadding(indicatorSpace, indicatorSpace, indicatorSpace, indicatorSpace);

indicator.setImageDrawable(unSelectedDrawable);

indicatorContainer.addView(indicator);

}

LoopPagerAdapter pagerAdapter = newLoopPagerAdapter(views);

mViewPager.setAdapter(pagerAdapter);

//設置當前item到Integer.MAX_VALUE中間的一個值,看起來像無論是往前滑還是往后滑都是ok的//如果不設置,用戶往左邊滑動的時候已經劃不動了inttargetItemPosition = Integer.MAX_VALUE/ 2- Integer.MAX_VALUE/ 2% itemCount;

mViewPager.setCurrentItem(targetItemPosition);

switchIndicator(targetItemPosition % itemCount);

mViewPager.addOnPageChangeListener(newViewPager.SimpleOnPageChangeListener() {

@Overridepublic voidonPageSelected(intposition) {

switchIndicator(position % itemCount);

}

});

startAutoPlay();

}

/*** 開始自動輪播*/public voidstartAutoPlay() {

stopAutoPlay(); // 避免重復消息if(isAutoPlay) {

mHandler.sendEmptyMessageDelayed(WHAT_AUTO_PLAY, autoPlayDuration);

}

}

@Overrideprotected voidonWindowVisibilityChanged(intvisibility) {

super.onWindowVisibilityChanged(visibility);

if(visibility == VISIBLE) {

startAutoPlay();

} else{

stopAutoPlay();

}

}

/*** 停止自動輪播*/public voidstopAutoPlay() {

if(isAutoPlay) {

mHandler.removeMessages(WHAT_AUTO_PLAY);

}

}

private voidsetSliderTransformDuration(intscrollDuration) {

try{

Field mScroller = ViewPager.class.getDeclaredField("mScroller");

mScroller.setAccessible(true);

FixedSpeedScroller fixedSpeedScroller = newFixedSpeedScroller(mViewPager.getContext(), null, scrollDuration);

mScroller.set(mViewPager, fixedSpeedScroller);

} catch(Exception e) {

e.printStackTrace();

}

}

@Overridepublic booleandispatchTouchEvent(MotionEvent ev) {

switch(ev.getAction()) {

caseMotionEvent.ACTION_DOWN:

stopAutoPlay();

break;

caseMotionEvent.ACTION_CANCEL:

caseMotionEvent.ACTION_UP:

startAutoPlay();

break;

}

return super.dispatchTouchEvent(ev);

}

/*** 切換指示器狀態**@paramcurrentPosition當前位置*/private voidswitchIndicator(intcurrentPosition) {

for(inti = 0; i < indicatorContainer.getChildCount(); i++) {

((ImageView) indicatorContainer.getChildAt(i)).setImageDrawable(i == currentPosition ? selectedDrawable: unSelectedDrawable);

}

}

public voidsetOnBannerItemClickListener(OnBannerItemClickListener onBannerItemClickListener) {

this.mOnBannerItemClickListener= onBannerItemClickListener;

}

@NonNullprivateFrameLayout getFrameLayoutView(Context context, String url, String title, final intposition) {

FrameLayout frameLayout = newFrameLayout(getContext());

FrameLayout.LayoutParams layoutParams = newFrameLayout.LayoutParams(LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);

layoutParams.gravity= Gravity.CENTER;

ImageView imageView = newImageView(getContext());

frameLayout.addView(imageView);

frameLayout.setOnClickListener(newOnClickListener() {

@Overridepublic voidonClick(View v) {

if(mOnBannerItemClickListener!= null) {

mOnBannerItemClickListener.onItemClick(position);

}

}

});

imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);

if(defaultImage!= 0){

Glide.with(getContext()).load(url).placeholder(defaultImage).centerCrop().into(imageView);

}else{

Glide.with(getContext()).load(url).centerCrop().into(imageView);

}

if(!TextUtils.isEmpty(title)) {

TextView textView = newTextView(getContext());

textView.setText(title);

textView.setTextColor(titleColor);

textView.setPadding(titlePadding, titlePadding, titlePadding, titlePadding);

textView.setBackgroundColor(titleBGColor);

textView.getPaint().setFakeBoldText(true);

layoutParams.gravity= Gravity.BOTTOM;

frameLayout.addView(textView, layoutParams);

}

returnframeLayout;

}

@NonNullprivateFrameLayout getFrameLayoutView(Integer res, String title, final intposition) {

FrameLayout frameLayout = newFrameLayout(getContext());

FrameLayout.LayoutParams layoutParams = newFrameLayout.LayoutParams(LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);

layoutParams.gravity= Gravity.CENTER;

ImageView imageView = newImageView(getContext());

frameLayout.addView(imageView);

frameLayout.setOnClickListener(newOnClickListener() {

@Overridepublic voidonClick(View v) {

if(mOnBannerItemClickListener!= null) {

mOnBannerItemClickListener.onItemClick(position);

}

}

});

imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);

Glide.with(getContext()).load(res).centerCrop().into(imageView);

if(!TextUtils.isEmpty(title)) {

TextView textView = newTextView(getContext());

textView.setText(title);

textView.setTextColor(titleColor);

textView.setPadding(titlePadding, titlePadding, titlePadding, titlePadding);

textView.setBackgroundColor(titleBGColor);

textView.getPaint().setFakeBoldText(true);

layoutParams.gravity= Gravity.BOTTOM;

frameLayout.addView(textView, layoutParams);

}

returnframeLayout;

}

public interfaceOnBannerItemClickListener {

voidonItemClick(intposition);

}

public classLoopPagerAdapter extendsPagerAdapter {

privateList views;

publicLoopPagerAdapter(List views) {

this.views= views;

}

@Overridepublic intgetCount() {

//Integer.MAX_VALUE = 2147483647returnInteger.MAX_VALUE;

}

@Overridepublic booleanisViewFromObject(View view, Object object) {

returnview == object;

}

@OverridepublicObject instantiateItem(ViewGroup container, intposition) {

if(views.size() > 0) {

//position % view.size()是指虛擬的position會在[0,view.size())之間循環View view = views.get(position % views.size());

if(container.equals(view.getParent())) {

container.removeView(view);

}

container.addView(view);

returnview;

}

return null;

}

@Overridepublic voiddestroyItem(ViewGroup container, intposition, Object object) {

}

}

public classFixedSpeedScroller extendsScroller {

private intmDuration= 1000;

publicFixedSpeedScroller(Context context) {

super(context);

}

publicFixedSpeedScroller(Context context, Interpolator interpolator) {

super(context, (android.view.animation.Interpolator) interpolator);

}

publicFixedSpeedScroller(Context context, Interpolator interpolator, intduration) {

this(context, interpolator);

mDuration= duration;

}

@Overridepublic voidstartScroll(intstartX, intstartY, intdx, intdy, intduration) {

// Ignore received duration, use fixed one insteadsuper.startScroll(startX, startY, dx, dy, mDuration);

}

@Overridepublic voidstartScroll(intstartX, intstartY, intdx, intdy) {

// Ignore received duration, use fixed one insteadsuper.startScroll(startX, startY, dx, dy, mDuration);

}

}

}

總結

以上是生活随笔為你收集整理的android 广告栏效果,实现android广告栏效果的全部內容,希望文章能夠幫你解決所遇到的問題。

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

主站蜘蛛池模板: 色www国产亚洲阿娇 自拍一区在线 | www.狠狠插 | 女人被狂躁c到高潮 | 日本黄色www | 99视频网| 香港三日本8a三级少妇三级99 | 天堂网在线中文 | 91网在线| 欧美一二三四五区 | 午夜国产| 国产在线视频卡一卡二 | 超碰人人人人人人人 | 午夜精品免费观看 | 美女av在线免费观看 | 精品成人一区 | 久久av在线播放 | 日韩精品视频观看 | 伦理黄色片| 97伊人 | 色屋在线| 91免费视频播放 | 蜜臀久久99精品久久一区二区 | 精久久 | 国产精品无码一区二区无人区多人 | 69xx欧美 | 中文字幕偷拍 | 手机成人在线视频 | 欧美大片大全 | 713电影免费播放国语 | 欧美xxxx黑人xyx性爽 | 免费禁漫天堂a3d | 日本免费黄网站 | 午夜寂寞视频 | 国产精品中文字幕在线观看 | 国产又粗又硬又黄的视频 | 四虎免费影视 | 99极品视频 | 免费亚洲网站 | 一女三黑人理论片在线 | 国产亚洲视频在线观看 | 爽爽窝窝午夜精品一区二区 | 黄色网www| 国产黄a三级 | 亚洲第一二区 | 熟女俱乐部一区二区 | 污网在线观看 | 爱爱一区 | 亚洲偷偷自拍 | 久久99久久精品 | 风流少妇 | 中国三级黄色 | 烈性摔跤 | 69中国xxxxxxxxx69 国产又爽又色 | 伊人久久一区 | av集中营| 国产美女一区二区三区 | 中文字幕无码精品亚洲 | 少妇视频 | 国产九一精品 | 欧美成人aa| 国产精品电影网 | 四虎精品在线播放 | 中文字字幕在线中文 | 国产孕妇一区二区三区 | 青青草自拍偷拍 | 黄色日批网站 | 青青在线视频 | 亚洲成人少妇 | 国产亚洲精品久久久久动 | 国产高潮国产高潮久久久91 | 精品无码国产一区二区三区51安 | 日本一区二区三区网站 | 欧美精品自拍偷拍 | 亚洲h在线观看 | 亚洲一区二区中文字幕 | 黄色av地址 | 成人91在线 | 国产视频在线观看一区 | bt天堂新版中文在线地址 | 国产日韩欧美一区二区东京热 | 黑人一级黄色片 | 亚洲美女在线播放 | 美女久久久久 | 亚洲人精品午夜射精日韩 | 久久久久久视 | www黄色片网站 | 久久超碰精品 | 国产美女引诱水电工 | 综合网五月天 | 一区黄色| 色就是色av | 高潮毛片7777777毛片 | 天天谢天天干 | 99在线观看免费 | 亚洲色网址 | 日本r级电影在线观看 | 三浦惠理子aⅴ一二三区 | 黄色免费视频 | 国产91在线视频观看 |