Alex Zaitsev
Alex Zaitsev

Reputation: 1781

ImageView.ScaleType.FitXY not works in code

I don't know why scaleType not works for this ImageView. widthGrayBlock is correct, I checked it with black background. ImageView has correct width and height but image resource doesn't fit it. Thank you.

        ImageView gray = new ImageView(mParentActivity);
        gray.setScaleType(ImageView.ScaleType.FIT_XY);
        gray.setAdjustViewBounds(true);
        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
                widthGrayBlock, LayoutParams.WRAP_CONTENT);
        params.setMargins(marginLeft, 0, 5, 0);
        progressLayout.addView(gray, 1, params);
        gray.setImageResource(R.drawable.schedule_bar_gray);
        //gray.setBackgroundColor(Color.BLACK);

Upvotes: 1

Views: 2271

Answers (1)

Sandra Mladenovic
Sandra Mladenovic

Reputation: 202

Try this in your xml

     android:scaleType="fitXY"
     android:layout_alignParentLeft="true"
     android:layout_centerVertical="true"

it's worked for me when i had a problem.

Upvotes: 1

Related Questions