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)文章
Android?Banner本地和網(wǎng)絡(luò)輪播圖使用介紹
大家好,本篇文章講的是Android?Banner本地和網(wǎng)絡(luò)輪播圖使用介紹,感興趣的同學(xué)趕快來看一看吧,希望本篇文章對你起到幫助2021-11-11Android OnFocuChangeListener焦點事件詳解
這篇文章主要為大家詳細介紹了Android OnFocuChangeListener焦點事件,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-09-09Android使用Shape實現(xiàn)ProgressBar樣式實例
本篇文章主要介紹了Android使用Shape實現(xiàn)ProgressBar樣式實例,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-04-04Android編程之手機壁紙WallPaper設(shè)置方法示例
這篇文章主要介紹了Android編程之手機壁紙WallPaper設(shè)置方法,結(jié)合實例形式分析了Android手機壁紙WallPaper的相關(guān)設(shè)置與使用技巧,需要的朋友可以參考下2017-08-08Android開發(fā)教程之ContentProvider數(shù)據(jù)存儲
這篇文章主要介紹了Android開發(fā)教程之ContentProvider數(shù)據(jù)存儲的相關(guān)資料,需要的朋友可以參考下2016-12-12簡單實現(xiàn)Android讀取網(wǎng)絡(luò)圖片到本地
這篇文章主要為大家詳細介紹了如何簡單實現(xiàn)Android讀取網(wǎng)絡(luò)圖片到本地的方法,感興趣的小伙伴們可以參考一下2016-08-08android教程之使用asynctask在后臺運行耗時任務(wù)
AsyncTask用在需要在ui線程中調(diào)用、在背景線程中執(zhí)行耗時任務(wù)、并且在ui線程中返回結(jié)果的場合。下面就是一個在背景中運行的AsyncTask的實現(xiàn)DownloadDBTask2014-02-02Android 應(yīng)用中跳轉(zhuǎn)到應(yīng)用市場評分示例
本篇文章主要介紹了Android 應(yīng)用中跳轉(zhuǎn)到應(yīng)用市場評分示例,非常具有實用價值,需要的朋友可以參考下。2017-02-02