android开发实践(1)——个人信息设置页面

android开发实践(1)——个人信息设置页面

前言

由于是小组合作,同组的大神已经把大部分的工作的都做好了,我就打打酱油了,添一块砖就好了_

连接真机

  • 手机开发者选项打开USB调试
    • 本人红米4a(对,就是那个499的),进入设置,连续点击关于手机->MIUI版本,开启开发者选项,然后打开更多设置->开发者选项->USB调试即可。
  • 问题:Installation failed with message Failed to establish session.
    It is possible that this issue is resolved by uninstalling an existing version of the apk if it is present, and then re-installing.
    • 解决方法
    1. 手机上 开发者选项里关闭MIUI优化
    2. android studio 中File —— Settings——Build,Execution,Deployment——Instant Run
      (2)将Enable Instant Run to hot swap code/resource changes on deploy(default enabled)的选择框取消

画界面

最顶部头像居中,下面用listview列出各信息

修改头像

  • 调用相册
    (***需权限 < uses-permission android:name=“android.permission.READ_EXTERNAL_STORAGE”/>***)

      public void onClick(View v) {
      //调用相册
      Intent intent = new Intent(Intent.ACTION_PICK,
              android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
      startActivityForResult(intent, 1);
      }
    
  • 上面调用了startActivityForResult,然后利用onActivityResult来对返回的信息进行处理

       @Override
          protected void onActivityResult(int requestCode, int resultCode, Intent data) {
              super.onActivityResult(requestCode, resultCode, data);
              //获取图片路径
              if (requestCode == 1 && resultCode == Activity.RESULT_OK && data != null) {
                  Uri selectedImage = data.getData();
                  String[] filePathColumns = {MediaStore.Images.Media.DATA};
                  Cursor c = getContentResolver().query(selectedImage, filePathColumns, null, null, null);
                  c.moveToFirst();
                  int columnIndex = c.getColumnIndex(filePathColumns[0]);
                  String imagePath = c.getString(columnIndex);
                  showImage(imagePath);
                  c.close();
              }
          }
      
          //加载图片(使用压缩读取技术)
          private void showImage(String imaePath){
              BitmapFactory.Options options = new BitmapFactory.Options();
              options.inJustDecodeBounds = true;
              BitmapFactory.decodeFile(imaePath, options);
              options.inSampleSize = 1;
              int side =  1000;//(int) getResources().getDimension(R.dimen.iv_personal_side);
              int a = options.outWidth/ side;
              options.inSampleSize = a;
              options.inJustDecodeBounds = false;
              Bitmap bm = BitmapFactory.decodeFile(imaePath, options);
              imageView.setImageBitmap(bm);
          }
    

不用压缩,则图片显示不出,报错:Bitmap too large to be uploaded into a texture

你可能感兴趣的:(android学习笔记)