zoukankan      html  css  js  c++  java
  • android 获取图库中展示到界面中

    layout:

    <LinearLayout 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"
          android:orientation="vertical"
        tools:context="com.example.useimage.MainActivity" >
    
        <Button
            android:onClick="selectImage"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="选择一个图片" />
        
         <ImageView 
             android:id="@+id/iv"
             android:layout_width="fill_parent"
            android:layout_height="fill_parent"
             />
    
    </LinearLayout>

    main_activtity

    package com.example.useimage;
    
    import android.content.Intent;
    import android.net.Uri;
    import android.os.Bundle;
    import android.support.v7.app.ActionBarActivity;
    import android.view.View;
    import android.widget.ImageView;
    
    
    public class MainActivity extends ActionBarActivity {
    
        private ImageView iv;
        
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            
            iv = (ImageView)findViewById(R.id.iv);
            
        }
        
        
        public void selectImage(View view)
        {
            
            Intent intent = new Intent();
            intent.setAction(Intent.ACTION_PICK);
            intent.setType("image/*");
            startActivityForResult(intent, 0);
            
        }
    
        @Override
        protected void onActivityResult(int arg0, int arg1, Intent data) {
            
            if(data!=null)
            {
                
                Uri uri = data.getData();
                iv.setImageURI(uri);
            }
            super.onActivityResult(arg0, arg1, data);
        }
    
    
    }
  • 相关阅读:
    链路追踪
    Zuul网关
    MyBatis批量插入
    自定义组件使用v-model
    正则表达式入门
    博客园主题1【备份】
    关于我
    input输入框内容规范正则总结
    实例003:完全平方数
    python基础day5dict
  • 原文地址:https://www.cnblogs.com/zoro-zero/p/3975845.html
Copyright © 2011-2022 走看看