How do I dynamically get and set the width and height of the ImageView?

Source: Internet
Author: User
Package com.pic;

Import android.app.Activity;
Import Android.os.Bundle;
Import Android.util.Log;
Import Android.view.ViewGroup.LayoutParams;
Import Android.widget.ImageView;

public class Pictest extends Activity {
Private final String TAG = "Pictrue Test!!!";
Private ImageView image;
private int height = 0;
private int width = 0;


@Override
public void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Setcontentview (R.layout.main);

Image = (ImageView) Findviewbyid (R.ID.IMAGEVIEW01);
Height = image.getheight ();
width = Image.getwidth ();
LOG.D (TAG, "Height:" + height);
LOG.D (TAG, "width:" + width);


Layoutparams para;
Para = Image.getlayoutparams ();

LOG.D (TAG, "layout height0:" + para.height);
LOG.D (TAG, "layout width0:" + para.width);

Para.height = 300;
Para.width = 300;
Image.setlayoutparams (para);

LOG.D (TAG, "layout height:" + para.height);
LOG.D (TAG, "layout width:" + para.width);

}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.