以编程方式减小ImageView的大小(使用java代码)

Nul*_*ion 1 android imageview

如何将imageview的大小减小到200x200?

这是我的实际代码:

 private ImageView splash;

    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        FrameLayout fl = new FrameLayout(this.getApplicationContext());
        splash = new ImageView(getApplicationContext());
        splash.setImageResource(R.drawable.logo);
        fl.addView(splash);
        fl.setForegroundGravity(Gravity.CENTER);
        fl.setBackgroundColor(Color.BLACK);
        setContentView(fl);
Run Code Online (Sandbox Code Playgroud)

Utt*_*tam 7

试试这个:

  ImageView image=(ImageView)findViewById(R.id.Image1);
  Bitmap bm=BitmapFactory.decodeResource(getResources(), R.drawable.sc01);
  int width=200;
  int height=200;
  Bitmap resizedbitmap=Bitmap.createScaledBitmap(bm, width, height, true);

  image.setImageBitmap(resizedbitmap);
Run Code Online (Sandbox Code Playgroud)