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

Android控件之ImageView用法實(shí)例分析

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

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

ImageView控件是一個(gè)圖片控件,負(fù)責(zé)顯示圖片。
以下模擬手機(jī)圖片查看器

目錄結(jié)構(gòu):

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;//記錄當(dāng)前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);
   }
  }
 };
}

運(yùn)行結(jié)果:

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

相關(guān)文章

  • Android?Studio實(shí)現(xiàn)智能聊天

    Android?Studio實(shí)現(xiàn)智能聊天

    這篇文章主要為大家詳細(xì)介紹了Android?Studio實(shí)現(xiàn)智能聊天,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-07-07
  • Android 自定義View實(shí)現(xiàn)任意布局的RadioGroup效果

    Android 自定義View實(shí)現(xiàn)任意布局的RadioGroup效果

    這篇文章主要介紹了Android 自定義View實(shí)現(xiàn)任意布局的RadioGroup,需要的朋友可以參考下
    2018-11-11
  • Android中Handler、Thread、HandlerThread三者的區(qū)別

    Android中Handler、Thread、HandlerThread三者的區(qū)別

    本文主要介紹了Android中Handler、Thread、HandlerThread三者的區(qū)別,文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-10-10
  • android開發(fā)權(quán)限詢問的示例代碼

    android開發(fā)權(quán)限詢問的示例代碼

    這篇文章主要介紹了android開發(fā)權(quán)限詢問的示例代碼,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2018-01-01
  • Flutter實(shí)現(xiàn)圖片濾鏡效果

    Flutter實(shí)現(xiàn)圖片濾鏡效果

    這篇文章主要介紹了Flutter如何實(shí)現(xiàn)圖片濾鏡效果,幫助大家更好的理解和學(xué)習(xí)使用Flutter,感興趣的朋友可以了解下
    2021-04-04
  • Android實(shí)現(xiàn)高德地圖首頁(yè)效果(下)

    Android實(shí)現(xiàn)高德地圖首頁(yè)效果(下)

    這篇文章主要為大家詳細(xì)介紹了基于Android實(shí)現(xiàn)高德地圖首頁(yè)效果下篇,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2023-08-08
  • Android仿微信微博多圖展示效果

    Android仿微信微博多圖展示效果

    這篇文章主要為大家詳細(xì)介紹了Android仿微信微博多圖展示效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-02-02
  • Android開發(fā)之獲取網(wǎng)絡(luò)鏈接狀態(tài)

    Android開發(fā)之獲取網(wǎng)絡(luò)鏈接狀態(tài)

    這篇文章主要介紹了Android獲取網(wǎng)絡(luò)鏈接狀態(tài)的方法,主要是通過ConnectivityManager類來完成的,需要的朋友可以參考下
    2014-08-08
  • RecyclerView的使用之HelloWorld

    RecyclerView的使用之HelloWorld

    RecyclerView是伴隨Android 5.0發(fā)布的新控件,是一種列表容器,Google意在用新的RecyclerView來取代老舊的ListView和GridView,它的使用靈活性和性能都要優(yōu)于ListView,通過本文給大家介紹RecyclerView的使用之HelloWorld,需要的朋友參考下
    2016-03-03
  • Android 實(shí)現(xiàn)控件懸浮效果實(shí)例代碼

    Android 實(shí)現(xiàn)控件懸浮效果實(shí)例代碼

    本篇文章主要介紹了Android 實(shí)現(xiàn)控件懸浮效果實(shí)例代碼,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2017-01-01

最新評(píng)論