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

Android實(shí)現(xiàn)仿Windows7圖片預(yù)覽窗格效果

 更新時(shí)間:2017年12月26日 10:25:23   作者:光仔December  
這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)仿Windows7圖片預(yù)覽窗格效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本實(shí)例將顯示類(lèi)似于windows7提供的圖片預(yù)覽窗格效果,單擊任意一張圖片,可以在右側(cè)顯示該圖片的預(yù)覽效果。

效果如圖所示:

具體實(shí)現(xiàn)方法:
res/layout/main.xml:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
 android:orientation="horizontal" 
 android:layout_width="fill_parent" 
 android:layout_height="fill_parent" 
 android:id="@+id/layout1" 
 > 
 <GridView android:id="@+id/gridView1" 
  android:layout_height="match_parent" 
  android:layout_width="440px" 
  android:layout_marginTop="10px" 
  android:horizontalSpacing="3px" 
  android:verticalSpacing="3px" 
  android:numColumns="3"/> 
 <!-- 添加一個(gè)圖像切換器 --> 
 <ImageSwitcher 
  android:id="@+id/imageSwitcher1" 
  android:padding="10px" 
  android:layout_width="match_parent" 
  android:layout_height="match_parent"/> 
</LinearLayout> 

MainActivity:

package com.example.test; 
 
import android.app.Activity; 
import android.os.Bundle; 
import android.view.View; 
import android.view.ViewGroup; 
import android.view.ViewGroup.LayoutParams; 
import android.view.animation.AnimationUtils; 
import android.widget.AdapterView; 
import android.widget.AdapterView.OnItemClickListener; 
import android.widget.BaseAdapter; 
import android.widget.GridView; 
import android.widget.ImageSwitcher; 
import android.widget.ImageView; 
import android.widget.ViewSwitcher.ViewFactory; 
 
public class MainActivity extends Activity { 
 private int[] imageId=new int []{R.drawable.img1,R.drawable.img2,R.drawable.img3,R.drawable.img4, 
   R.drawable.img5,R.drawable.img6,R.drawable.img7,R.drawable.img8,R.drawable.img9}; 
 private ImageSwitcher imageSwitcher; 
 @Override 
 public void onCreate(Bundle savedInstanceState) { 
  super.onCreate(savedInstanceState); 
  setContentView(R.layout.main); 
   
  imageSwitcher=(ImageSwitcher)findViewById(R.id.imageSwitcher1);//獲取圖像切換器 
  //設(shè)置動(dòng)畫(huà)效果 
  imageSwitcher.setInAnimation(AnimationUtils.loadAnimation(this, android.R.anim.fade_in));//設(shè)置淡入動(dòng)畫(huà) 
  imageSwitcher.setOutAnimation(AnimationUtils.loadAnimation(this, android.R.anim.fade_out));//設(shè)置淡出動(dòng)畫(huà) 
  imageSwitcher.setFactory(new ViewFactory() { 
    
   @Override 
   public View makeView() { 
    //實(shí)例化一個(gè)ImageView對(duì)象 
    ImageView imageView=new ImageView(MainActivity.this); 
    //設(shè)置保持縱橫比居中縮放圖像 
    imageView.setScaleType(ImageView.ScaleType.FIT_CENTER); 
    imageView.setLayoutParams(new ImageSwitcher.LayoutParams( 
      LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT)); 
    return imageView;//返回imageView對(duì)象 
   } 
  }); 
  imageSwitcher.setImageResource(R.drawable.img3);//設(shè)置默認(rèn)顯示的圖像 
   
   
  GridView gridview=(GridView)findViewById(R.id.gridView1); 
  BaseAdapter adapter=new BaseAdapter(){ 
 
 
   @Override 
   public View getView(int position, View convertView, ViewGroup parent) { 
    ImageView imageView = null;//聲明一個(gè)ImageView對(duì)象 
    if(convertView==null){ 
     imageView=new ImageView(MainActivity.this);//實(shí)例化ImageView對(duì)象 
     /****************設(shè)置圖像的寬度和高度*******************/ 
     imageView.setAdjustViewBounds(true); 
     imageView.setMaxWidth(150); 
     imageView.setMaxHeight(113); 
     /*********************************************************/ 
     imageView.setPadding(5, 5, 5, 5); 
    }else{ 
     imageView=(ImageView)convertView; 
    } 
    imageView.setImageResource(imageId[position]); 
    return imageView; 
   } 
    
   //功能:獲得當(dāng)前選項(xiàng)的id 
   @Override 
   public long getItemId(int position) { 
    return position; 
   } 
    
   //功能:獲得當(dāng)前選項(xiàng) 
   @Override 
   public Object getItem(int position) { 
    return position; 
   } 
    
   //獲得數(shù)量 
   @Override 
   public int getCount() { 
    return imageId.length; 
   } 
  }; 
  gridview.setAdapter(adapter); 
  gridview.setOnItemClickListener(new OnItemClickListener() { 
 
 
   @Override 
   public void onItemClick(AdapterView<?> parent, View view, int position, 
     long id) { 
     //顯示選中的照片 
     imageSwitcher.setImageResource(imageId[position]); 
   } 
  }); 
 } 
} 

運(yùn)行效果與開(kāi)頭描述相同,成功實(shí)現(xiàn)。

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Android裁剪圖片為圓形圖片的實(shí)現(xiàn)原理與代碼

    Android裁剪圖片為圓形圖片的實(shí)現(xiàn)原理與代碼

    這個(gè)方法是根據(jù)傳入的圖片的高度(height)和寬度(width)決定的,如果是 width <= height時(shí),則會(huì)裁剪高度,裁剪的區(qū)域是寬度不變高度從頂部到寬度width的長(zhǎng)度
    2013-01-01
  • Android實(shí)現(xiàn)獲取meta-data和build.gradle的值

    Android實(shí)現(xiàn)獲取meta-data和build.gradle的值

    這篇文章主要介紹了Android實(shí)現(xiàn)獲取meta-data和build.gradle的值,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2020-03-03
  • Android編程設(shè)計(jì)模式之命令模式詳解

    Android編程設(shè)計(jì)模式之命令模式詳解

    這篇文章主要介紹了Android編程設(shè)計(jì)模式之命令模式,詳細(xì)分析了命令模式的概念、功能、使用場(chǎng)景、用法及相關(guān)操作注意事項(xiàng),需要的朋友可以參考下
    2017-12-12
  • Android利用Intent實(shí)現(xiàn)讀取圖片操作

    Android利用Intent實(shí)現(xiàn)讀取圖片操作

    這篇文章主要為大家詳細(xì)介紹了Android利用Intent實(shí)現(xiàn)讀取圖片操作的相關(guān)資料,感興趣的小伙伴們可以參考一下
    2016-06-06
  • Gradle的安裝和環(huán)境變量的配置詳解

    Gradle的安裝和環(huán)境變量的配置詳解

    這篇文章主要介紹了Gradle的安裝和環(huán)境變量的配置詳解,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2020-07-07
  • Android 實(shí)現(xiàn)云知聲版離線語(yǔ)音合成

    Android 實(shí)現(xiàn)云知聲版離線語(yǔ)音合成

    這篇文章主要介紹了Android 實(shí)現(xiàn)云知聲版離線語(yǔ)音合成,目前云知聲提供免費(fèi)的離線TTS,功能也比較簡(jiǎn)單,合成的語(yǔ)音也比較生硬,如果對(duì)合成的語(yǔ)音要求不高的話可以考慮接入。具體合成需要的小伙伴可以參考下面文章內(nèi)容
    2022-06-06
  • Android Canvas之drawBitmap方法案例詳解

    Android Canvas之drawBitmap方法案例詳解

    這篇文章主要介紹了Android Canvas之drawBitmap方法案例詳解,本篇文章通過(guò)簡(jiǎn)要的案例,講解了該項(xiàng)技術(shù)的了解與使用,以下就是詳細(xì)內(nèi)容,需要的朋友可以參考下
    2021-08-08
  • Android apk完整性檢測(cè)的實(shí)現(xiàn)思路和代碼實(shí)現(xiàn)

    Android apk完整性檢測(cè)的實(shí)現(xiàn)思路和代碼實(shí)現(xiàn)

    這篇文章主要介紹了Android apk完整性檢測(cè)的實(shí)現(xiàn)思路和代碼實(shí)現(xiàn),本文通過(guò)示例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友參考下吧
    2023-12-12
  • Android實(shí)現(xiàn)簡(jiǎn)單的popupwindow提示框

    Android實(shí)現(xiàn)簡(jiǎn)單的popupwindow提示框

    這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)簡(jiǎn)單的popupwindow提示框,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-10-10
  • Android中ActionBar和ToolBar添加返回箭頭的實(shí)例代碼

    Android中ActionBar和ToolBar添加返回箭頭的實(shí)例代碼

    這篇文章主要介紹了Android中ActionBar和ToolBar添加返回箭頭的實(shí)例代碼,需要的朋友可以參考下
    2017-09-09

最新評(píng)論