简体   繁体   English

如何从Java File调整XML文件上的imageview大小? (Android)

[英]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. 我很困惑如何设置selectedImage的大小,以便它们可以以相同大小显示在xml文件中。 Plese help me!! 请帮我! and how to set size of other image in xml file so that it has same size also. 以及如何在xml文件中设置其他图像的大小,使其也具有相同的大小。 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));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 imageview源在java文件和xml文件中? - imageview source in the java file and the xml file? 如何从Java文件(Android)创建.xml文件? - How to create .xml file from java file (Android)? 我们如何从服务器获取xml矢量图像文件并在android studio的imageview中查看 - how can we get the xml vector image file from server & view it in the imageview in android studio 如何使 Java 从 XML 文件中调用字符串(在 Android Studio 中) - How to make the Java to call a String from a XML file(In Android Studio) 如何在Java中将变量值从Java转换为xml文件? - How to get variable values from java to xml file in android? 如何使用 java ZC31B32364CE19CA8FCD150A417ECCE8 调整 base64 ImageView 的大小? - How resize base64 ImageView using java android? 如何使用 java 将 imageView 调整为以像素为单位的特定大小? (在android工作室) - How to resize an imageView to a certain size in pixels with java? (In android studio) 如何在Android中从URL加载没有文件扩展名的图像到ImageView - How to load image without file extension from URL to ImageView in Android Android Studio:如何将外部文件(来自相机的照片)设置为imageview - Android Studio : How to set an external file(photo from the camera) to an imageview android-从.java文件控制XML文件中的NullPointerException - android - NullPointerException in Controlling XML file from .java file
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM