欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android開發(fā)實(shí)現(xiàn)的圖片點(diǎn)擊切換功能示例

 更新時(shí)間:2019年04月23日 08:52:26   作者:水中魚之1999  
這篇文章主要介紹了Android開發(fā)實(shí)現(xiàn)的圖片點(diǎn)擊切換功能,涉及Android ImageView組件創(chuàng)建、布局及實(shí)現(xiàn)圖形切換相關(guān)操作技巧,需要的朋友可以參考下

本文實(shí)例講述了Android開發(fā)實(shí)現(xiàn)的圖片點(diǎn)擊切換功能。分享給大家供大家參考,具體如下:

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>

效果

更多關(guān)于Android相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Android圖形與圖像處理技巧總結(jié)》、《Android開發(fā)入門與進(jìn)階教程》、《Android調(diào)試技巧與常見問題解決方法匯總》、《Android基本組件用法總結(jié)》、《Android視圖View技巧總結(jié)》、《Android布局layout技巧總結(jié)》及《Android控件用法總結(jié)

希望本文所述對(duì)大家Android程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論