Image View not Wrapping Contents
Add the following fields to ImageView: android:scaleType=”fitXY” android:adjustViewBounds=”true”
Add the following fields to ImageView: android:scaleType=”fitXY” android:adjustViewBounds=”true”
The best option is to subclass ImageView yourself, overriding the measure pass: public class SquareImageView extends ImageView { … @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); int width = getMeasuredWidth(); setMeasuredDimension(width, width); } … }
Try the adjustViewBounds attribute: android:adjustViewBounds=”true”
You need to set the LayoutParams of the ViewGroup the ImageView is sitting in. For example if your ImageView is inside a LinearLayout, then you create a LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(30, 30); yourImageView.setLayoutParams(layoutParams); This is because it’s the parent of the View that needs to know what size to allocate to the View.
Try this android:adjustViewBounds=”true”
I have solved this by creating a java-class that you include in your layout-file: public class DynamicImageView extends ImageView { public DynamicImageView(final Context context, final AttributeSet attrs) { super(context, attrs); } @Override protected void onMeasure(final int widthMeasureSpec, final int heightMeasureSpec) { final Drawable d = this.getDrawable(); if (d != null) { // ceil not round … Read more
You can do this with a single image using something like this: //get the image view ImageView imageView = (ImageView)findViewById(R.id.ImageView); //set the ontouch listener imageView.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: { ImageView view = (ImageView) v; //overlay is black with transparency of 0x77 (119) view.getDrawable().setColorFilter(0x77000000,PorterDuff.Mode.SRC_ATOP); … Read more
Ok, I have a working solution. The prompt from Darko made me look again at the ImageView class (thanks) and have applied the transformation using a Matrix (as i originally suspected but did not have success on my first attempt!). In my custom imageView class I call setScaleType(ScaleType.MATRIX) after super() in the constructor, and have … Read more
I wanted to achieve the same goal as you, so I wrote the following method which does exactly that if you pass it an ImageView and a list of references to image drawables. ImageView demoImage = (ImageView) findViewById(R.id.DemoImage); int imagesToShow[] = { R.drawable.image1, R.drawable.image2,R.drawable.image3 }; animate(demoImage, imagesToShow, 0,false); private void animate(final ImageView imageView, final int … Read more
Okay, I don’t foresee any more answers on this one, so what I ended up going with for now is just a solution for rectangular images. I’ve used the following NinePatch: along with the appropriate padding in XML: <ImageView android:id=”@+id/image_test” android:background=”@drawable/drop_shadow” android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:paddingLeft=”6px” android:paddingTop=”4px” android:paddingRight=”8px” android:paddingBottom=”9px” android:src=”https://stackoverflow.com/questions/3693234/@drawable/pic1″ /> to get a fairly good result: … Read more