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

Android中ImageView用法實(shí)例分析

 更新時(shí)間:2016年02月01日 11:08:37   作者:馬到成功  
這篇文章主要介紹了Android中ImageView用法,結(jié)合實(shí)例形式較為詳細(xì)的分析了ImageView控件的功能,屬性設(shè)置與使用相關(guān)技巧,需要的朋友可以參考下

本文實(shí)例分析了Android中ImageView用法。分享給大家供大家參考,具體如下:

猜牌游戲大家可能以前都玩過,這里我們用這個(gè)小游戲來說明ImageView的用法。

首先,在res/drawable中引入三張牌:分別是梅花7,梅花8,梅花9

然后在res/layout/main.xml中配置一個(gè)TextView,三個(gè)ImageView以及一個(gè)Button

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:orientation="vertical" >
  <TextView
    android:id="@+id/tv"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/hello" />
  <Button 
    android:id="@+id/button"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    />
  <ImageView 
    android:id="@+id/iv07"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    />
  <ImageView 
    android:id="@+id/iv08"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    />
  <ImageView 
    android:id="@+id/iv09"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    />
</LinearLayout>

程序如下所示:

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
public class A04Activity extends Activity {
 private ImageView iv07,iv08,iv09;
 private TextView tv;
 private Button b;
 private int[] s={
  R.drawable.puke07,
  R.drawable.puke08,
  R.drawable.puke09
  };
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    iv07=(ImageView)findViewById(R.id.iv07);
    iv08=(ImageView)findViewById(R.id.iv08);
    iv09=(ImageView)findViewById(R.id.iv09);
    tv=(TextView)findViewById(R.id.tv);
    b=(Button)findViewById(R.id.button);
    randon();
    //下面以ImageView的OnClickListener()方法對選擇的不同牌做不同的反應(yīng)
  iv07.setOnClickListener(new OnClickListener(){
  @Override
  public void onClick(View v) {
  // TODO Auto-generated method stub  
  iv07.setImageDrawable(getResources().getDrawable(s[0]));
  iv08.setImageDrawable(getResources().getDrawable(s[1]));
  iv09.setImageDrawable(getResources().getDrawable(s[2]));
  iv08.setAlpha(100);  //對沒有選擇的牌做灰暗處理
  iv09.setAlpha(100);
  if(s[0]==R.drawable.puke08){ //如果選擇的牌是梅花8的話就猜對了
   tv.setText("恭喜你,猜對了?。?!");
  }
  else{
   tv.setText("親,猜錯了,要不要再來一次?");
  }
  }
  });
  iv08.setOnClickListener(new OnClickListener(){
  @Override
  public void onClick(View v) {
  // TODO Auto-generated method stub
  iv07.setImageDrawable(getResources().getDrawable(s[0]));
  iv08.setImageDrawable(getResources().getDrawable(s[1]));
  iv09.setImageDrawable(getResources().getDrawable(s[2]));
  iv07.setAlpha(100);
  iv09.setAlpha(100);
  if(s[1]==R.drawable.puke08){
   tv.setText("恭喜你,猜對了?。。?);
  }
  else{
   tv.setText("親,猜錯了,要不要再來一次?");
  }
  }
  });
  iv09.setOnClickListener(new OnClickListener(){
  @Override
  public void onClick(View v) {
  // TODO Auto-generated method stub
  iv07.setImageDrawable(getResources().getDrawable(s[0]));
  iv08.setImageDrawable(getResources().getDrawable(s[1]));
  iv09.setImageDrawable(getResources().getDrawable(s[2]));
  iv07.setAlpha(100);
  iv08.setAlpha(100);
  if(s[2]==R.drawable.puke09){
   tv.setText("恭喜你,猜對了?。?!");
  }
  else{
   tv.setText("親,猜錯了,要不要再來一次?");
  }
  }
  });
  b.setOnClickListener(new OnClickListener(){
  @Override
  public void onClick(View v) {
  // TODO Auto-generated method stub
  tv.setText("猜猜梅花8在哪里");
  iv07.setImageDrawable(getResources().getDrawable(R.drawable.puke00));
  //剛開始的時(shí)候顯示撲克牌的背面
  iv08.setImageDrawable(getResources().getDrawable(R.drawable.puke00));
  iv09.setImageDrawable(getResources().getDrawable(R.drawable.puke00));
  iv07.setAlpha(255);//
  iv08.setAlpha(255);
  iv09.setAlpha(255);
  randon();
  }
  });
  }
//randon方法是進(jìn)行隨機(jī)地洗牌
  public void randon(){
   for(int i=0;i<s.length;i++){
   int tmp=s[i];
   int a=(int)(Math.random()*2);
   s[i]=s[a];
   s[a]=tmp;
   }
  }
}

更多關(guān)于Android相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Android開發(fā)入門與進(jìn)階教程》、《Android基本組件用法總結(jié)》及《Android控件用法總結(jié)

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

相關(guān)文章

  • Android?LineChart繪制折線圖的示例詳解

    Android?LineChart繪制折線圖的示例詳解

    這篇文章主要為大家想想介紹了Android?RecyclerLineChart實(shí)現(xiàn)繪制折線圖的相關(guān)資料,有需要的朋友可以借鑒參考下,希望能夠有所幫助
    2023-03-03
  • Android自定義控件實(shí)現(xiàn)隨手指移動的小球

    Android自定義控件實(shí)現(xiàn)隨手指移動的小球

    這篇文章主要為大家詳細(xì)介紹了Android自定義控件實(shí)現(xiàn)隨手指移動的小球,隨著手指觸摸移動而移動的效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2016-10-10
  • Android開發(fā)之a(chǎn)ctiviti節(jié)點(diǎn)跳轉(zhuǎn)

    Android開發(fā)之a(chǎn)ctiviti節(jié)點(diǎn)跳轉(zhuǎn)

    這篇文章主要介紹了Android開發(fā)之a(chǎn)ctiviti節(jié)點(diǎn)跳轉(zhuǎn)的相關(guān)資料,需要的朋友可以參考下
    2016-04-04
  • Flutter?彈性布局基石flex算法flexible示例詳解

    Flutter?彈性布局基石flex算法flexible示例詳解

    這篇文章主要為大家介紹了Flutter?彈性布局基石flex算法flexible示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-12-12
  • Android繪制旋轉(zhuǎn)動畫方法詳解

    Android繪制旋轉(zhuǎn)動畫方法詳解

    這篇文章主要介紹了Android如何采用RotateAnimation繪制一個(gè)旋轉(zhuǎn)動畫,文中的實(shí)現(xiàn)方法講解詳細(xì),感興趣的小伙伴可以跟隨小編一起試一試
    2022-01-01
  • 淺談Android編碼規(guī)范及命名規(guī)范

    淺談Android編碼規(guī)范及命名規(guī)范

    本文主要總結(jié)一下Android項(xiàng)目的開發(fā)規(guī)范:1、編碼規(guī)范 2、命名規(guī)范。有需要的朋友可以看下
    2016-12-12
  • Android如何用自定義View實(shí)現(xiàn)雪花效果

    Android如何用自定義View實(shí)現(xiàn)雪花效果

    這篇文章主要介紹了Android如何用自定義View實(shí)現(xiàn)雪花效果,對特效感興趣的同學(xué)可以參考下
    2021-04-04
  • Kotlin+buildSrc更好的管理Gradle依賴譯文

    Kotlin+buildSrc更好的管理Gradle依賴譯文

    這篇文章主要為大家介紹了Kotlin+buildSrc更好的管理Gradle依賴譯文及示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-06-06
  • 如何更改Dialog的標(biāo)題與按鈕顏色詳解

    如何更改Dialog的標(biāo)題與按鈕顏色詳解

    這篇文章主要給大家介紹了關(guān)于如何更改Dialog的標(biāo)題與按鈕顏色的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考借鑒,下面跟著小編來一起學(xué)習(xí)學(xué)習(xí)吧。
    2017-08-08
  • Android TextView字體顏色設(shè)置方法小結(jié)

    Android TextView字體顏色設(shè)置方法小結(jié)

    這篇文章主要介紹了Android TextView字體顏色設(shè)置方法,結(jié)合實(shí)例形式總結(jié)分析了Android開發(fā)中TextView設(shè)置字體顏色的常用技巧,需要的朋友可以參考下
    2016-02-02

最新評論