就是不管屏幕是1024像素还是800像素还是480像素宽度,图片宽度总是占据屏幕宽度的10%,高度根据宽度保持比例改变,请问能实现吗?是用imageview吗?

解决方案 »

  1.   


       /**
     * 创建一个缩小或放大的新图片
     * 
     * @param resourcesID
     * @param scr_width 
     * @param res_height 
     * @return
     */
    private Bitmap CreatMatrixBitmap(int resourcesID, float scr_width, float res_height) {
    Bitmap bitMap = null;
    bitMap = BitmapFactory.decodeResource(sResources, resourcesID);
    int bitWidth = bitMap.getWidth();
    int bitHeight = bitMap.getHeight();
    float scaleWidth = scr_width / (float) bitWidth;
    float scaleHeight = res_height / (float) bitHeight;
    Matrix matrix = new Matrix();
    matrix.postScale(scaleWidth, scaleHeight);
    bitMap = Bitmap.createBitmap(bitMap, 0, 0, bitWidth, bitHeight, matrix, true);
    return bitMap;
    }
      

  2.   

     ImageView 自带比例伸缩的设下就可以了
     ImageView  iv=(ImageView)this.findViewById(R.id.imageView1);;
     iv.setScaleType(ImageView.ScaleType.FIT_CENTER);