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

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

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

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

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

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

代碼-布局:

Android開發(fā)實(shí)現(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;//圖片顯示序列號(hào) @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() {//實(shí)現(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); } /** * 判斷是否由對(duì)象生成界面 */ @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://m.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://m.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://m.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://m.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對(duì)象 private ViewPagerAdapter vpAdapter;//定義ViewPager適配器 private ArrayList<View> views;//定義一個(gè)ArrayList來存放View private static final int[] pics = {R.drawable.one,R.drawable.two,R.drawable.san,R.drawable.si};//引導(dǎo)圖片資源 private ImageView[] points;//底部小點(diǎn)的圖片 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();//初始化底部小點(diǎn) } private void initPoint() { LinearLayout linearLayout = (LinearLayout) findViewById(R.id.ll); points = new ImageView[pics.length]; //循環(huán)取得小點(diǎn)圖片 for (int i = 0; i < pics.length; i++) { points[i] = (ImageView) linearLayout.getChildAt(i);//得到一個(gè)LinearLayout下面的每一個(gè)子元素 points[i].setEnabled(true);//默認(rèn)都設(shè)為灰色 points[i].setOnClickListener(this);//給每個(gè)小點(diǎn)設(shè)置監(jiān)聽 points[i].setTag(i);//設(shè)置位置tag,方便取出與當(dāng)前位置對(duì)應(yīng) } currentIndex = 0;//設(shè)置當(dāng)面默認(rèn)的位置 points[currentIndex].setEnabled(false);//設(shè)置為白色,即選中狀態(tài) } private void initView() { views = new ArrayList<View>();//實(shí)例化ArrayList對(duì)象 viewPager = (ViewPager) findViewById(R.id.viewpager);//實(shí)例化ViewPager vpAdapter = new ViewPagerAdapter(views);//實(shí)例化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ā)實(shí)現(xiàn)圖片切換APP

另外一種效果圖:

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

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

標(biāo)簽: Android
相關(guān)文章:
日本不卡不码高清免费观看,久久国产精品久久w女人spa,黄色aa久久,三上悠亚国产精品一区二区三区
亚洲精品国模| 亚洲午夜久久| 麻豆91精品视频| 美国三级日本三级久久99| 午夜久久福利| 日韩精品久久理论片| 国产精品2023| 国产成人精品亚洲线观看| 日韩精品影视| 视频一区在线播放| 国产伦精品一区二区三区在线播放| 国产精品永久| 91精品xxx在线观看| 国产视频一区在线观看一区免费| 日韩国产欧美一区二区三区| 欧美成a人片免费观看久久五月天| 日韩欧美不卡| 亚洲人成高清| 国产精品一区三区在线观看| 日韩电影免费网站| 日本大胆欧美人术艺术动态| 国产探花一区在线观看| 国内自拍视频一区二区三区| 99久久久久国产精品| 美女91精品| 欧美激情一区| 欧美中文一区二区| 日韩精品亚洲专区| 国产传媒在线| 亚洲精品在线a| 国产一区二区三区四区二区| 国产午夜精品一区二区三区欧美 | 国产日韩在线观看视频| 色婷婷色综合| 热久久免费视频| 久久久久久婷| 色8久久久久| 日韩综合精品| 日韩av不卡一区二区| 精品三级久久| 911亚洲精品| 鲁鲁在线中文| 一区二区三区午夜视频| 激情国产在线| 欧美在线网站| 老司机精品在线| 喷白浆一区二区| 激情亚洲影院在线观看| 青青国产精品| 91九色精品| 久久中文字幕一区二区| 免费国产亚洲视频| 久久中文字幕av一区二区不卡| 日韩激情一区二区| 午夜精品一区二区三区国产| 麻豆成人av在线| 亚洲精品一二| 黄色不卡一区| 国产传媒av在线| 亚洲欧洲专区| 99国产精品| 日本一二区不卡| 久久狠狠久久| 亚洲永久精品唐人导航网址| 国产精品7m凸凹视频分类| 久久爱www成人| 亚州精品视频| 亚洲在线网站| 成人精品中文字幕| 日韩av自拍| 国产精品久一| 国产免费av一区二区三区| 亚洲不卡视频| 日韩一区欧美二区| 日产精品一区二区| 麻豆成人av在线| 国产精品亚洲综合久久| 亚洲一级大片| 蜜桃视频在线观看一区| 国产亚洲一区在线| 在线视频日韩| 国产精品日本| 欧美日韩国产精品一区二区亚洲| 蜜桃av.网站在线观看| 成年男女免费视频网站不卡| 精品亚洲免a| 久久永久免费| 黄色欧美在线| av在线最新| 精品国产亚洲日本| 久久99国产精品视频| 久久亚洲黄色| 福利欧美精品在线| 亚洲天堂免费电影| 韩国三级一区| 一区在线免费观看| 制服诱惑一区二区| 99国产精品自拍| 国产欧美亚洲一区| 日本成人中文字幕| 激情国产在线| 成人午夜网址| 免费看av不卡| 欧美1区2区3区| 91视频一区| 中文字幕在线视频网站| 久久精品亚洲欧美日韩精品中文字幕| 99精品综合| 麻豆精品91| 亚洲91网站| 久久av中文| 日本美女一区| 国产女优一区| 亚洲精品无播放器在线播放| 日韩精品亚洲专区在线观看| 国产欧美日韩视频在线| 日韩成人a**站| 91成人网在线观看| 一区二区三区国产盗摄| 免费观看日韩电影| 久久精品99国产国产精| 精品国产鲁一鲁****| 久久久777| 久久最新视频| 欧美激情三区| 999国产精品| 亚洲精品字幕| 免费亚洲婷婷| 五月天综合网站| 国产色噜噜噜91在线精品| 中文字幕高清在线播放| 伊人久久亚洲影院| 国产精品亚洲二区| 一区二区精品伦理...| 蜜桃视频欧美| 国产亚洲精品美女久久久久久久久久| 精品三级在线| 91久久视频| 国产精品成人国产| 黄色成人在线网址| 国产日韩精品视频一区二区三区| 中文字幕在线视频久| 国产精品嫩草99av在线| 国产精品久久久久9999高清| 欧美日韩亚洲在线观看| 日本不卡一二三区黄网| 国产成人黄色| 亚洲欧美在线综合| 久久久久久久久成人| 精品日产乱码久久久久久仙踪林| 婷婷丁香综合| 国产成人精品亚洲线观看| 日韩精品不卡一区二区| 亚洲一级大片| 色婷婷久久久| 日韩av一区二区在线影视| 欧美一区二区三区高清视频| 丝袜诱惑制服诱惑色一区在线观看 | 首页国产精品| 欧美搞黄网站| 国产精品黄色片| 日韩精品麻豆| 欧美日韩1区| 欧美日韩免费观看视频| 青青青国产精品| 婷婷亚洲五月色综合| 国产欧美69| 视频一区二区中文字幕| 久久精品国产99| 中文字幕一区二区三区四区久久 | 亚洲电影在线一区二区三区| 国产精品美女午夜爽爽| 欧美资源在线| 精品亚洲自拍| 亚洲婷婷丁香| 1000部精品久久久久久久久| 国产精品对白| 亚洲2区在线| 黑丝一区二区三区| 久久久亚洲一区| 麻豆国产欧美日韩综合精品二区| 免播放器亚洲| 国产中文一区| 久久中文字幕一区二区三区| 亚洲欧美日本国产专区一区| 蜜臀国产一区| 美女国产一区二区三区| 日韩一二三区在线观看| 日韩精品一区二区三区免费观看| 精品伊人久久| 欧美日韩亚洲一区在线观看| 日韩在线一二三区| 久久精品高清| av亚洲一区二区三区| 免费亚洲婷婷| 国产精品xxx| 国产精品亚洲产品| 免费不卡在线观看| 视频一区二区国产| 国产精品毛片|