最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android控件之ImageView用法實例分析

 更新時間:2015年09月12日 11:15:32   作者:Ruthless  
這篇文章主要介紹了Android控件之ImageView用法,以實例形式較為詳細的分析了ImageView控件用于顯示圖片的使用方法,具有一定參考借鑒價值,需要的朋友可以參考下

本文實例講述了Android控件之ImageView用法。分享給大家供大家參考。具體如下:

ImageView控件是一個圖片控件,負責顯示圖片。
以下模擬手機圖片查看器

目錄結構:

main.xml布局文件:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:orientation="vertical"
 android:layout_width="fill_parent"
 android:layout_height="fill_parent">
 <ImageView android:id="@+id/imageView"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:layout_gravity="center_horizontal"
  android:src="@drawable/p1"/>
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="horizontal"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:layout_gravity="center_horizontal">
  <Button android:id="@+id/previous"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:text="上一張"
   android:layout_gravity="center_horizontal"/>
  <Button android:id="@+id/alpha_plus"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:text="透明度增加"
   android:layout_gravity="center_horizontal"/>
  <Button android:id="@+id/alpha_minus"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:text="透明度減少"
   android:layout_gravity="center_horizontal"/>
  <Button android:id="@+id/next"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:text="下一張"
   android:layout_gravity="center_horizontal"/>
 </LinearLayout>
</LinearLayout>

ImageViewActivity類:

package com.ljq.iv;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
public class ImageViewActivity extends Activity {
 private ImageView imageView=null;
 private Button previous=null;//上一張
 private Button next=null;//下一張
 private Button alpha_plus=null;//透明度增加
 private Button alpha_minus=null;//透明度減少
 private int currentImgId=0;//記錄當前ImageView顯示的圖片id
 private int alpha=255;//記錄ImageView的透明度
 int [] imgId = {   //ImageView顯示的圖片數(shù)組
   R.drawable.p1, 
   R.drawable.p2,
   R.drawable.p3,
   R.drawable.p4,
   R.drawable.p5,
   R.drawable.p6,
   R.drawable.p7,
   R.drawable.p8,
  };
 @Override
 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main);
  imageView=(ImageView)findViewById(R.id.imageView);
  previous=(Button)findViewById(R.id.previous);
  next=(Button)findViewById(R.id.next);
  alpha_plus=(Button)findViewById(R.id.alpha_plus);
  alpha_minus=(Button)findViewById(R.id.alpha_minus);
  previous.setOnClickListener(listener);
  next.setOnClickListener(listener);
  alpha_plus.setOnClickListener(listener);
  alpha_minus.setOnClickListener(listener);
 }
 private View.OnClickListener listener = new View.OnClickListener(){
  public void onClick(View v) {
   if(v==previous){
    currentImgId=(currentImgId-1+imgId.length)%imgId.length;
    imageView.setImageResource(imgId[currentImgId]);
   }
   if(v==next){
    currentImgId=(currentImgId+1)%imgId.length;
    imageView.setImageResource(imgId[currentImgId]);
   }
   if(v==alpha_plus){
    alpha+=10;
    if(alpha>255){
     alpha=255;
    }
    imageView.setAlpha(alpha);
   }
   if(v==alpha_minus){
    alpha-=10;
    if(alpha<0){
     alpha=0;
    }
    imageView.setAlpha(alpha);
   }
  }
 };
}

運行結果:

希望本文所述對大家的Android程序設計有所幫助。

相關文章

  • Android自定義PopupWindow小案例

    Android自定義PopupWindow小案例

    這篇文章主要為大家詳細介紹了Android自定義PopupWindow小案例,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2016-11-11
  • flutter封裝點擊菜單工具欄組件checkBox多選版

    flutter封裝點擊菜單工具欄組件checkBox多選版

    這篇文章主要為大家介紹了flutter封裝一個點擊菜單工具欄組件,checkBox多選版的示例示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2022-05-05
  • Android實現(xiàn)顏色選取圓盤

    Android實現(xiàn)顏色選取圓盤

    這篇文章主要為大家詳細介紹了Android實現(xiàn)顏色選取圓盤,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2018-06-06
  • Android的異步任務AsyncTask詳解

    Android的異步任務AsyncTask詳解

    本文給大家介紹的是Android的異步任務AsyncTask,在Android中實現(xiàn)異步任務機制有兩種方式,Handler和AsyncTask。今天我們先來主要談下ASYNCTASK。
    2015-07-07
  • Android中Glide加載圓形圖片和圓角圖片實例代碼

    Android中Glide加載圓形圖片和圓角圖片實例代碼

    本篇文章主要介紹了Android中Glide加載圓形圖片和圓角圖片實例代碼,具體一定的參考價值,有興趣的可以了解一下
    2017-05-05
  • Android鬧鐘設置的解決方案

    Android鬧鐘設置的解決方案

    這篇文章主要為大家詳細介紹了Android鬧鐘設置的解決方案,避免開發(fā)Android設置鬧鐘的坑,感興趣的小伙伴們可以參考一下
    2016-07-07
  • Android用于校驗集合參數(shù)的小封裝示例

    Android用于校驗集合參數(shù)的小封裝示例

    本篇文章主要介紹了Android-用于校驗集合參數(shù)的小封裝示例,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-10-10
  • 詳解Flutter中視頻播放器插件的使用教程

    詳解Flutter中視頻播放器插件的使用教程

    視頻播放器插件是可用于Flutter的常用插件之一,在這篇文章中,將學習如何應用視頻播放器插件以及控制視頻播放器的不同功能,感興趣的可以了解一下
    2022-02-02
  • popupwindow焦點問題解決方案

    popupwindow焦點問題解決方案

    在android 開發(fā)過程中,總會遇到一些問題,比如popupwindow焦點問題等等,我們該如何解決呢?需要的朋友可以了解下
    2012-11-11
  • 更新Android Studio 3.0碰到的問題小結

    更新Android Studio 3.0碰到的問題小結

    本文是小編給大家分享的更新Android Studio 3.0碰到的問題小結,非常不錯,具有參考借鑒價值,需要的朋友參考下吧
    2017-11-11

最新評論

平陆县| 伊金霍洛旗| 湾仔区| 北川| 清镇市| 丹江口市| 柘荣县| 桂平市| 望都县| 沾化县| 鹿泉市| 丽水市| 白玉县| 襄樊市| 封开县| 东丰县| 临邑县| 万盛区| 中山市| 营口市| 吴桥县| 全州县| 长治市| 汝阳县| 靖宇县| 信丰县| 永昌县| 福建省| 柏乡县| 大庆市| 比如县| 开原市| 乌拉特前旗| 突泉县| 彭山县| 文山县| 清水河县| 大庆市| 土默特左旗| 綦江县| 临江市|