简体   繁体   中英

How to resize imageview on XML file from Java File? (Android)

I have cod below :

Gallery gallery = (Gallery) findViewById(R.id.gallery1);
    selectedImage=(ImageView)findViewById(R.id.imageView1);
    gallery.setSpacing(1);
    gallery.setAdapter(new ImageAdapter(this));
     // clicklistener for Gallery
    gallery.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
            // show the selected Image
            selectedImage.setImageResource(mImageIds[position]);
            // resize the selected Image

        }
    });

I confused how to set the size of selectedImage, so that they can appear in xml file with same size. Plese help me!! and how to set size of other image in xml file so that it has same size also. Thank you

Use it:

selectedImage.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT, 0f));

or

selectedImage.setLayoutParams(new LinearLayout.LayoutParams(100dp, 100dp, 0f));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM