I want to Aspect Fill my image. The size of my image is 1242x168. What I want is that if my screen is small my image will be cut and left align but it seems that it keeps on being aspect fit.
Here is my code
DisplayMetrics displaymetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
int device_width = displaymetrics.widthPixels;
float density = getResources().getDisplayMetrics().density;
float dpWidth = displaymetrics.widthPixels / density;
if(dpWidth >= 768) {
int aspectRatio = (int) (0.135 * device_width);
gifImageView.getLayoutParams().height = aspectRatio;
gifImageView.getLayoutParams().width = device_width;
}
Here is my xml
<pl.droidsonroids.gif.GifImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/displayImage"
android:layout_gravity="left"
android:scaleType="fitStart"
android:background="@color/red"
android:adjustViewBounds="true"
/>
I tried using android:scaleType="centerCrop" but it is crop in center I wanted to cut the right side that is why I wanted to be left align.