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

首頁 > 系統 > Android > 正文

Android中ImageView實現選擇本地圖片并顯示功能

2019-12-12 03:11:39
字體:
來源:轉載
供稿:網友

運行結果:

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

一個隱式意圖

布局文件:

<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);  } } 

以上就是本文的全部內容,希望本文的內容對大家的學習或者工作能帶來一定的幫助,同時也希望多多支持武林網!

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 金秀| 栾城县| 洪湖市| 金华市| 毕节市| 连云港市| 巴林右旗| 庆云县| 仁怀市| 龙井市| 花莲市| 清徐县| 新余市| 社旗县| 炎陵县| 建水县| 梅州市| 大埔县| 双峰县| 芒康县| 菏泽市| 托里县| 崇左市| 界首市| 白河县| 东阳市| 岱山县| 象州县| 陵川县| 息烽县| 杭锦后旗| 毕节市| 二手房| 吕梁市| 吉林市| 扎赉特旗| 长沙县| 从江县| 晋中市| 丽水市| 湘潭县|