国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 系統(tǒng) > Android > 正文

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

2019-10-23 18:32:36
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

運(yùn)行結(jié)果:

imageview顯示本地圖片,imageview,加載本地,android

模擬器圖庫(kù)就三張 沒辦法~畫質(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í)也希望多多支持VEVB武林網(wǎng)!


注:相關(guān)教程知識(shí)閱讀請(qǐng)移步到Android開發(fā)頻道。
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 霍山县| 青海省| 团风县| 勃利县| 绥化市| 资中县| 芜湖县| 天等县| 东丰县| 三原县| 班玛县| 南乐县| 沧州市| 青河县| 福海县| 赣州市| 长沙县| 三河市| 珲春市| 洪江市| 五峰| 贵南县| 南平市| 怀化市| 贵阳市| 遵化市| 当涂县| 南安市| 即墨市| 涪陵区| 玛沁县| 禹城市| 买车| 巩留县| 阳原县| 依兰县| 灵石县| 东乡| 揭阳市| 四川省| 宣化县|