Android中ImageView實(shí)現(xiàn)選擇本地圖片并顯示功能
運(yùn)行結(jié)果:

模擬器圖庫(kù)就三張 沒(méi)辦法~畫質(zhì)挺感人~
一個(gè)隱式意圖
布局文件:
<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);
}
}
以上就是本文的全部?jī)?nèi)容,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作能帶來(lái)一定的幫助,同時(shí)也希望多多支持腳本之家!
相關(guān)文章
在當(dāng)前Activity之上創(chuàng)建懸浮view之WindowManager懸浮窗效果
這篇文章主要介紹了在當(dāng)前Activity之上創(chuàng)建懸浮view之WindowManager懸浮窗效果的相關(guān)資料,需要的朋友可以參考下2016-01-01
Android ProgressDialog的實(shí)例詳解
這篇文章主要介紹了Android ProgressDialog的實(shí)例詳解的相關(guān)資料,Android 開發(fā)項(xiàng)目的時(shí)候經(jīng)常會(huì)遇到耗時(shí)的操作,這里就講下Android ProgressDialog的應(yīng)用,需要的朋友可以參考下2017-07-07
Android開發(fā)adb.exe'' and can be executed.錯(cuò)誤解決方法
這篇文章主要介紹了Android開發(fā)adb.exe' and can be executed.錯(cuò)誤解決方法,本文分析了問(wèn)題的可能原因并給出了排查步驟,需要的朋友可以參考下2015-06-06
Android判斷當(dāng)前App是在前臺(tái)還是在后臺(tái)
這篇文章主要為大家詳細(xì)介紹了Android判斷當(dāng)前App是在前臺(tái)還是在后臺(tái)的方法,感興趣的小伙伴們可以參考一下2016-08-08
Android自定義View之漸變色折線圖的實(shí)現(xiàn)
折線圖的實(shí)現(xiàn)方法在github上有很多開源的程序,但是對(duì)于初學(xué)者來(lái)講,簡(jiǎn)單一點(diǎn)的教程可能更容易入門,下面這篇文章主要給大家介紹了關(guān)于Android自定義View之漸變色折線圖的相關(guān)資料,需要的朋友可以參考下2022-04-04

