日本不卡不码高清免费观看,久久国产精品久久w女人spa,黄色aa久久,三上悠亚国产精品一区二区三区

您的位置:首頁技術(shù)文章
文章詳情頁

Android開發(fā)實現(xiàn)圖片切換APP

瀏覽:133日期:2022-09-21 11:40:50

本文實例為大家分享了Android開發(fā)實現(xiàn)圖片切換APP的具體代碼,供大家參考,具體內(nèi)容如下

本次介紹的是關(guān)于圖片切換的APP,這里實現(xiàn)了兩種切換效果;不同的效果針對不同的情況,兩種效果的代碼都會介紹:

代碼-布局:

Android開發(fā)實現(xiàn)圖片切換APP

main.xml的代碼:

<?xml version='1.0' encoding='utf-8'?><android.support.constraint.ConstraintLayout xmlns:android='http://schemas.android.com/apk/res/android' xmlns:tools='http://schemas.android.com/tools' xmlns:app='http://schemas.android.com/apk/res-auto' android:layout_width='match_parent' android:layout_height='match_parent' tools:context='.MainActivity'> <ImageSwitcher android: android:layout_width='match_parent' android:layout_height='243dp' android:layout_marginTop='68dp' app:layout_constraintEnd_toEndOf='parent' app:layout_constraintHorizontal_bias='0.0' app:layout_constraintStart_toStartOf='parent' app:layout_constraintTop_toTopOf='parent' /> <LinearLayout android: android:layout_width='match_parent' android:layout_height='wrap_content' android:layout_marginTop='68dp' android:orientation='horizontal' android:paddingTop='15dp' app:layout_constraintEnd_toEndOf='parent' app:layout_constraintStart_toStartOf='parent' app:layout_constraintTop_toBottomOf='@+id/is_1'> <Button android: android:layout_width='0dip' android:layout_height='wrap_content' android:layout_marginLeft='15dp' android:layout_marginRight='15dp' android:layout_weight='1' android:background='@drawable/shape_button_main' android:text='下一張' android:textColor='#ffffff' android:textSize='18dp' /> <Button android: android:layout_width='0dip' android:layout_height='wrap_content' android:layout_marginLeft='15dp' android:layout_marginRight='15dp' android:layout_weight='1' android:background='@drawable/shape_button_main' android:text='上一張' android:textColor='#ffffff' android:textSize='18dp' /> </LinearLayout> <Button android: android:layout_width='176dp' android:layout_height='80dp' android:layout_marginTop='8dp' android:layout_marginBottom='16dp' android:background='@drawable/shape_button_main' android:text='另外一種效果' android:textSize='20dp' app:layout_constraintBottom_toBottomOf='parent' app:layout_constraintEnd_toEndOf='parent' app:layout_constraintStart_toStartOf='parent' app:layout_constraintTop_toBottomOf='@+id/linearLayout' /></android.support.constraint.ConstraintLayout>

mainactivity的代碼:

package com.example.wuluo.yanqi;import android.content.Intent;import android.support.v7.app.AppCompatActivity;import android.os.Bundle;import android.view.View;import android.widget.Button;import android.widget.ImageSwitcher;import android.widget.ImageView;import android.widget.ViewSwitcher;public class MainActivity extends AppCompatActivity implements View.OnClickListener,ViewSwitcher.ViewFactory{ private ImageSwitcher is_1; private Button btn_next; private Button btn_previous; private Button btn_3; private int image[]={R.drawable.tian1,R.drawable.tian2,R.drawable.tian3,R.drawable.tian4};//圖片的id數(shù)組 private int imageIndex=0;//圖片顯示序列號 @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); is_1=(ImageSwitcher) findViewById(R.id.is_1); btn_next=(Button) findViewById(R.id.btn_next); btn_previous=(Button) findViewById(R.id.btn_previous); btn_3=(Button)findViewById(R.id.btn_3); btn_previous.setOnClickListener(this); btn_next.setOnClickListener(this); btn_3.setOnClickListener(this); init(); //設(shè)置Factory } @Override public void onClick(View view) { if (view.getId()==R.id.btn_next){ imageIndex++; if(imageIndex>3){ imageIndex=0; } is_1.setInAnimation(this,R.anim.left_in); is_1.setOutAnimation(this,R.anim.right_out); }else if(view.getId()==R.id.btn_previous){ imageIndex--; if(imageIndex<0){ imageIndex=image.length-1; } is_1.setInAnimation(this,R.anim.right_in); is_1.setOutAnimation(this,R.anim.left_out); }else if(view.getId()==R.id.btn_3){ Intent intent=new Intent(); intent.setClass(this,other2.class); startActivity(intent); } is_1.setImageResource(image[imageIndex]); } @Override public View makeView() {//實現(xiàn)viewFactory接口.生成imageview ImageView imageView=new ImageView(this); return imageView; } private void init(){//初始化imageSwitch is_1.setFactory(this); is_1.setImageResource(image[imageIndex]); }}

ViewPagerAdapter的代碼:

package com.example.wuluo.yanqi;/** * Created by wuluo on 2018/12/21 */import android.support.v4.view.PagerAdapter;import android.support.v4.view.ViewPager;import android.view.View;import java.util.ArrayList;public class ViewPagerAdapter extends PagerAdapter { //界面列表 private ArrayList<View> views; public ViewPagerAdapter(ArrayList<View> views) { this.views = views; } /** * 獲得當(dāng)前界面數(shù) */ @Override public int getCount() { if (views != null) { return views.size(); } return 0; } /** * 初始化position位置的界面 */ @Override public Object instantiateItem(View view, int position) { ((ViewPager) view).addView(views.get(position), 0); return views.get(position); } /** * 判斷是否由對象生成界面 */ @Override public boolean isViewFromObject(View view, Object arg1) { return (view == arg1); } /** * 銷毀position位置的界面 */ @Override public void destroyItem(View view, int position, Object arg2) { ((ViewPager) view).removeView(views.get(position)); }}

other2.xml布局的代碼:

<?xml version='1.0' encoding='utf-8'?><android.support.constraint.ConstraintLayout xmlns:android='http://schemas.android.com/apk/res/android' xmlns:app='http://schemas.android.com/apk/res-auto' xmlns:tools='http://schemas.android.com/tools' android:layout_width='match_parent' android:layout_height='match_parent' tools:context='.other2'> <android.support.v4.view.ViewPager android: android:layout_width='fill_parent' android:layout_height='fill_parent' app:layout_constraintBottom_toBottomOf='parent' app:layout_constraintEnd_toEndOf='parent' app:layout_constraintHorizontal_bias='0.0' app:layout_constraintStart_toStartOf='parent' app:layout_constraintTop_toTopOf='parent' app:layout_constraintVertical_bias='0.0' /> <LinearLayout android: android:layout_width='wrap_content' android:layout_height='wrap_content' android:layout_alignParentBottom='true' android:layout_centerHorizontal='true' android:layout_marginStart='8dp' android:layout_marginEnd='8dp' android:layout_marginBottom='8dp' android:orientation='horizontal' app:layout_constraintBottom_toBottomOf='@+id/viewpager' app:layout_constraintEnd_toEndOf='parent' app:layout_constraintStart_toStartOf='parent'> <ImageView android:layout_width='wrap_content' android:layout_height='40dp' android:layout_gravity='center_vertical' android:clickable='true' android:padding='15.0dip' android:src='http://www.b3g6.com/bcjs/@drawable/point' /> <ImageView android:layout_width='wrap_content' android:layout_height='40dp' android:layout_gravity='center_vertical' android:clickable='true' android:padding='15.0dip' android:src='http://www.b3g6.com/bcjs/@drawable/point' /> <ImageView android:layout_width='wrap_content' android:layout_height='40dp' android:layout_gravity='center_vertical' android:clickable='true' android:padding='15.0dip' android:src='http://www.b3g6.com/bcjs/@drawable/point' /> <ImageView android:layout_width='wrap_content' android:layout_height='40dp' android:layout_gravity='center_vertical' android:clickable='true' android:padding='15.0dip' android:src='http://www.b3g6.com/bcjs/@drawable/point' /> </LinearLayout></android.support.constraint.ConstraintLayout>

other2activity的代碼:

package com.example.wuluo.yanqi;import android.support.v4.view.ViewPager;import android.support.v7.app.ActionBar;import android.support.v7.app.AppCompatActivity;import android.os.Bundle;import android.view.View;import android.widget.ImageView;import android.widget.LinearLayout;import java.util.ArrayList;public class other2 extends AppCompatActivity implements View.OnClickListener,ViewPager.OnPageChangeListener{ private ViewPager viewPager;//定義ViewPager對象 private ViewPagerAdapter vpAdapter;//定義ViewPager適配器 private ArrayList<View> views;//定義一個ArrayList來存放View private static final int[] pics = {R.drawable.one,R.drawable.two,R.drawable.san,R.drawable.si};//引導(dǎo)圖片資源 private ImageView[] points;//底部小點的圖片 private int currentIndex; @Override protected void onCreate(Bundle savedInstanceState) { ActionBar actionBar=getSupportActionBar();// actionBar.hide();//隱藏標(biāo)題欄 super.onCreate(savedInstanceState); setContentView(R.layout.activity_other2); initView(); initData(); } private void initData() { LinearLayout.LayoutParams mParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.FILL_PARENT); //初始化引導(dǎo)圖片列表 for(int i=0; i<pics.length; i++) { ImageView iv = new ImageView(this); iv.setLayoutParams(mParams); iv.setImageResource(pics[i]); views.add(iv); } viewPager.setAdapter(vpAdapter); //設(shè)置數(shù)據(jù) viewPager.setOnPageChangeListener(this);//設(shè)置監(jiān)聽 initPoint();//初始化底部小點 } private void initPoint() { LinearLayout linearLayout = (LinearLayout) findViewById(R.id.ll); points = new ImageView[pics.length]; //循環(huán)取得小點圖片 for (int i = 0; i < pics.length; i++) { points[i] = (ImageView) linearLayout.getChildAt(i);//得到一個LinearLayout下面的每一個子元素 points[i].setEnabled(true);//默認(rèn)都設(shè)為灰色 points[i].setOnClickListener(this);//給每個小點設(shè)置監(jiān)聽 points[i].setTag(i);//設(shè)置位置tag,方便取出與當(dāng)前位置對應(yīng) } currentIndex = 0;//設(shè)置當(dāng)面默認(rèn)的位置 points[currentIndex].setEnabled(false);//設(shè)置為白色,即選中狀態(tài) } private void initView() { views = new ArrayList<View>();//實例化ArrayList對象 viewPager = (ViewPager) findViewById(R.id.viewpager);//實例化ViewPager vpAdapter = new ViewPagerAdapter(views);//實例化ViewPager適配器 } @Override public void onPageScrolled(int i, float v, int i1) { } @Override public void onPageSelected(int i) { setCurDot(i); } @Override public void onPageScrollStateChanged(int i) { } @Override public void onClick(View view) { int position = (Integer)view.getTag(); setCurView(position); setCurDot(position); } private void setCurView(int position){ if (position < 0 || position >= pics.length) { return; } viewPager.setCurrentItem(position); } private void setCurDot(int positon){ if (positon < 0 || positon > pics.length - 1 || currentIndex == positon) { return; } points[positon].setEnabled(false); points[currentIndex].setEnabled(true); currentIndex = positon; }}

最后的效果圖:

Android開發(fā)實現(xiàn)圖片切換APP

另外一種效果圖:

Android開發(fā)實現(xiàn)圖片切換APP

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。

標(biāo)簽: Android
相關(guān)文章:
日本不卡不码高清免费观看,久久国产精品久久w女人spa,黄色aa久久,三上悠亚国产精品一区二区三区
久久国产视频网| 婷婷综合福利| 亚洲午夜91| 国产亚洲一区二区三区啪| 国产精品丝袜xxxxxxx| 开心激情综合| 欧美在线资源| 欧美精品91| 日韩精品亚洲专区| 中文字幕一区二区三区日韩精品| 国产精品久久久久久久久久10秀| 国产精品一区二区免费福利视频| 手机精品视频在线观看| 天堂资源在线亚洲| 久久久久91| 国产精品99久久免费观看| 久久亚洲美女| 国产精品老牛| 91久久午夜| 欧美在线综合| 视频一区二区欧美| 亚洲视频二区| 日韩国产欧美三级| 日韩精品视频在线看| 伊人久久亚洲| 91成人在线精品视频| 国产欧美一区二区色老头| 欧美国产视频| av综合电影网站| 亚洲啊v在线| 精品国产欧美| 欧美中文一区二区| 欧美综合二区| 国产一区二区精品福利地址| 美女av在线免费看| 久久人人99| 亚洲免费观看高清完整版在线观| 日韩国产一二三区| 国产精品麻豆久久| 亚洲一区区二区| 国产麻豆精品久久| 久久九九精品| 国产精一区二区| 色婷婷精品视频| 日韩精品一区二区三区av| 深夜日韩欧美| 中文在线免费视频| 日本亚洲最大的色成网站www | 成人av动漫在线观看| 国产视频一区三区| 久久爱www.| 香蕉久久国产| 国产精品久久乐| 精品一区二区三区亚洲| 欧美日韩在线网站| 亚洲一级黄色| 久久伊人国产| 亚洲1区在线| 欧美1级日本1级| 国产精品99久久精品| 亚洲精品成a人ⅴ香蕉片| 日韩欧美三级| 国产精品亚洲片在线播放| 亚洲一区二区三区高清不卡| 国产成年精品| 国产精品免费精品自在线观看| 一区二区视频欧美| 久久91导航| 国产福利一区二区三区在线播放| 美女被久久久| 国产日韩电影| 久久av影视| 日韩精品免费观看视频| 亚洲成人精品| zzzwww在线看片免费| 国产日韩亚洲欧美精品| 喷白浆一区二区| 欧美日韩国产免费观看| 久久国产主播| 久久久夜精品| 激情婷婷久久| 夜久久久久久| 亚洲视频综合| 国产一区清纯| 激情综合在线| 久久一区二区中文字幕| 日韩综合在线| 水蜜桃久久夜色精品一区| 国产成人久久| 久久久久国产一区二区| 久久免费大视频| 91精品一区国产高清在线gif| 成人啊v在线| 久久久五月天| 在线综合亚洲| 亚洲日本免费电影| 日本麻豆一区二区三区视频| 国产精品九九| 亚洲不卡系列| 蜜桃视频在线观看一区| 91视频久久| 一区二区三区视频免费观看| 免播放器亚洲一区| 国产一二在线播放| 亚洲九九精品| 国产精品精品国产一区二区| 亚洲激情久久| 久久99精品久久久久久园产越南| 日韩在线欧美| 久久狠狠久久| 亚洲精一区二区三区| 韩国精品主播一区二区在线观看| 亚洲一区有码| 日本高清不卡一区二区三区视频| 日韩久久99| 米奇777超碰欧美日韩亚洲| 亚洲激情另类| 国产网站在线| 欧美精品国产一区| 天堂av在线一区| а√天堂中文在线资源8| 日韩精品一区二区三区中文| 九一成人免费视频| 亚洲精品在线二区| 日韩在线免费| 日韩一区欧美二区| 日韩精品电影| 欧美日韩精品免费观看视频完整| 久久午夜影院| 蜜桃av.网站在线观看| 99久久精品网| 欧美女激情福利| 日韩精品久久久久久久软件91| 麻豆成人91精品二区三区| 午夜影院一区| 亚洲精品欧美| 精品国产91| 不卡av一区二区| 国产欧美在线观看免费| 人人精品亚洲| 五月激激激综合网色播| 欧美1级日本1级| 午夜精品成人av| 999久久久亚洲| 丁香六月综合| 久久毛片亚洲| 99国产精品久久久久久久| 亚洲二区精品| 亚洲一二三区视频| 欧美有码在线| 美腿丝袜亚洲一区| 久久国产精品色av免费看| 三级亚洲高清视频| 精品日韩视频| 亚洲综合另类| 欧美特黄视频| 亚洲精一区二区三区| 日韩精品成人在线观看| 国产欧美三级| 国产一区日韩| 久久五月天小说| 米奇777超碰欧美日韩亚洲| 免费中文字幕日韩欧美| 青青草国产成人99久久| 欧美精品第一区| 久久久久91| 蜜桃视频一区二区三区| 国产欧美自拍一区| 日本久久成人网| 视频一区二区三区在线| 国产精品白浆| 久久精品123| 中文字幕日韩高清在线| 蜜桃精品视频| 欧美日韩三区| 青青草视频一区| 黄色在线观看www| 爽好多水快深点欧美视频| 国产精品日韩精品中文字幕| 久久九九电影| 日韩欧美久久| 在线亚洲人成| 中文字幕av亚洲精品一部二部| 精品午夜av| 中国女人久久久| 国产精品成人自拍| 久久狠狠婷婷| 国产午夜一区| 国产伊人精品| 国产精品久久| 国产婷婷精品| 国产精品.xx视频.xxtv| 亚洲国内精品| 捆绑调教美女网站视频一区| 欧美特黄一区| 亚洲欧洲高清| 日韩av三区| 亚洲美洲欧洲综合国产一区| 美女国产精品久久久| 91久久久久|