I have a picture with a Match_Parent width and a height of 160dp and below all sorts of texts. The 4-inch looks fine! I need to make it so that with large screens, for example, if the screen is larger than 5 inches, the picture also increases without losing proportions!
1 answer
Described before how to make ResizableImageView :
public class ResizableImageView extends ImageView { public ResizableImageView(Context context, AttributeSet attrs) { super(context, attrs); } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec){ Drawable d = getDrawable(); if(d!=null){ int width = MeasureSpec.getSize(widthMeasureSpec); int height = (int) Math.ceil((float) width * (float) d.getIntrinsicHeight() / (float) d.getIntrinsicWidth()); setMeasuredDimension(width, height); }else{ super.onMeasure(widthMeasureSpec, heightMeasureSpec); } } } The image will occupy the entire width of the container, and then adjust the height to the desired proportions.
Instead of the usual ImageView , do this in the markup:
<ru.your.package.ResizableImageView android:id="@+id/imageView1" android:layout_width="match_parent" android:layout_height="160dp" android:src="@drawable/ivHeader" /> - Thanks, I'll try ... - DevOma
- And where to register my picture ID pictures for example ivHeader? - DevOma
- @Omuradil
<ru.your.package.ResizableImageView android:id="@+id/imageView1" android:layout_width="match_parent" android:layout_height="160dp" android:src="@drawable/ivHeader" />- Suvitruf ♦ - I have a gray background instead of a picture! What is the problem? Of course, I registered my package! - DevOma
- oneYou can also use the
android:adjustViewBounds. It is just for the image to retain the original aspect. Only it does not work at allscaleTypeand everything seems to be correct only with API 18. - xkor
|
Drawable Importer-a to generate all screen sizes and that's all - redL1nelayoutsome - redL1ne