imageview设置资源图片

    xiaoxiao2021-12-14  24

    以背景的形式 进行设置图片

    缺点 : 图片容易变形 优点: 可以不用关心图片的大小 直接填充窗体

    image2.setBackground(getResources().getDrawable(R.drawable.blackk));//变形 image2.setBackgroundResource(R.drawable.blackk);//变形 image2.setBackgroundDrawable(getResources().getDrawable(R.drawable.blackk));变形

    以 设置图片 的形式设置资源

    缺点 : 与窗体不能完美结合 优点: 图片不会变形

    image2.setImageDrawable(getResources().getDrawable(R.drawable.blackk)); //不会变形 String path=Environment.getExternalStorageDirectory()+File.separator+"test1.jpg"; Bitmap bm = BitmapFactory.decodeFile(path); image2.setImageBitmap(bm);//不会变形 image2.setImageResource(R.drawable.blackk);//不会变形

    安卓交流群 : 595856941

    转载请注明原文地址: https://ju.6miu.com/read-970675.html

    最新回复(0)