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

Android中ImageView實現(xiàn)選擇本地圖片并顯示功能

 更新時間:2017年04月05日 09:57:49   作者:甄情  
本文主要介紹了android中ImageView實現(xiàn)選擇本地圖片并顯示功能的示例代碼。具有很好的參考價值。下面跟著小編一起來看下吧

運行結(jié)果:

模擬器圖庫就三張 沒辦法~畫質(zhì)挺感人~

一個隱式意圖

布局文件:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
 xmlns:tools="http://schemas.android.com/tools" 
 android:layout_width="match_parent" 
 android:layout_height="match_parent" > 
 <ImageView 
  android:id="@+id/image_choose" 
  android:layout_width="250dp" 
  android:layout_height="250dp" 
  android:background="#CC0000" 
  android:layout_centerHorizontal="true" 
  android:layout_marginTop="30dp" 
  android:src="@drawable/default_bg" 
  android:padding="5dp" 
  /> 
</RelativeLayout> 

MainActivity.class

package com.example.chooseimage; 
import android.os.Bundle; 
import android.provider.MediaStore; 
import android.app.Activity; 
import android.content.Intent; 
import android.view.View; 
import android.view.View.OnClickListener; 
import android.view.Window; 
import android.widget.ImageView; 
public class MainActivity extends Activity implements OnClickListener { 
 private ImageView image_choose; 
 @Override 
 protected void onCreate(Bundle savedInstanceState) { 
  super.onCreate(savedInstanceState); 
  requestWindowFeature(Window.FEATURE_NO_TITLE); 
  setContentView(R.layout.activity_main); 
  image_choose = (ImageView) findViewById(R.id.image_choose); 
  image_choose.setOnClickListener(this); 
 } 
 @Override 
 public void onClick(View v) { 
  // TODO Auto-generated method stub 
  switch (v.getId()) { 
  case R.id.image_choose: { 
   Intent intent = new Intent(Intent.ACTION_PICK, null); 
   intent.setDataAndType(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, 
     "image/*"); 
   startActivityForResult(intent, 0x1); 
   break; 
  } 
  } 
 } 
 @Override 
 protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
  // TODO Auto-generated method stub 
  if (requestCode == 0x1 && resultCode == RESULT_OK) { 
   if (data != null) { 
    image_choose.setImageURI(data.getData()); 
   } 
  } 
  super.onActivityResult(requestCode, resultCode, data); 
 } 
} 

以上就是本文的全部內(nèi)容,希望本文的內(nèi)容對大家的學(xué)習(xí)或者工作能帶來一定的幫助,同時也希望多多支持腳本之家!

相關(guān)文章

最新評論