本篇文章為大家展示了怎么在Android中實(shí)現(xiàn)一個(gè)圖片點(diǎn)擊切換功能,內(nèi)容簡(jiǎn)明扼要并且容易理解,絕對(duì)能使你眼前一亮,通過這篇文章的詳細(xì)介紹希望你能有所收獲。
開江網(wǎng)站建設(shè)公司創(chuàng)新互聯(lián)公司,開江網(wǎng)站設(shè)計(jì)制作,有大型網(wǎng)站制作公司豐富經(jīng)驗(yàn)。已為開江超過千家提供企業(yè)網(wǎng)站建設(shè)服務(wù)。企業(yè)網(wǎng)站搭建\成都外貿(mào)網(wǎng)站建設(shè)公司要多少錢,請(qǐng)找那個(gè)售后服務(wù)好的開江做網(wǎng)站的公司定做!
java 代碼
public class MainActivity extends AppCompatActivity { //定義一個(gè)訪問圖片的數(shù)組 int[] images = new int[]{ R.drawable.java, R.drawable.javaee, R.drawable.swift, R.drawable.ajax, R.drawable.html, }; //用于圖片切換 int currenImg = 0; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //獲取Linearlayout布局容器 LinearLayout main = (LinearLayout) findViewById(R.id.root); //創(chuàng)建ImageView組件 final ImageView image = new ImageView(this); //將ImageView組建添加到linearlayout布局中 main.addView(image); //初始化顯示第一張圖片 image.setImageResource(images[0]); image.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { image.setImageResource(images[++currenImg % images.length]); } }); } }
xml 文件
<?xml version="1.0" encoding="utf-8"?> <LinearLayout 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:id="@+id/root" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context=".MainActivity"> </LinearLayout>
上述內(nèi)容就是怎么在Android中實(shí)現(xiàn)一個(gè)圖片點(diǎn)擊切換功能,你們學(xué)到知識(shí)或技能了嗎?如果還想學(xué)到更多技能或者豐富自己的知識(shí)儲(chǔ)備,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。
新聞名稱:怎么在Android中實(shí)現(xiàn)一個(gè)圖片點(diǎn)擊切換功能
本文URL:http://chinadenli.net/article6/gisoig.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供App設(shè)計(jì)、靜態(tài)網(wǎng)站、外貿(mào)網(wǎng)站建設(shè)、網(wǎng)站維護(hù)、品牌網(wǎng)站建設(shè)、面包屑導(dǎo)航
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)