Reputation: 47
I have one activity, and I set imageview element to match parent with one of my background image with dimensions: 1440x2560 . I need to make this image on fullscrean. But whenever I put that image using scaleType="fitXY" I get this:
XML layout:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.backgroundApp.SecondActivity">
<ImageView
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:srcCompat="@drawable/background"
android:scaleType="fitXY"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TextView"/>
</LinearLayout>
</android.support.v4.widget.DrawerLayout>
Activity:
package com.backgroundApp;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class SecondActivity extends AppCompatActivity {
ActionBar actionBar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
actionBar = getSupportActionBar();
actionBar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#004d40")));
}
}
Upvotes: 2
Views: 3183
Reputation: 707
change
app:srcCompat="@drawable/background"
to
android:src="@drawable/xxxxx"
Upvotes: 0
Reputation: 69689
setAdjustViewBounds(boolean adjustViewBounds)
Set this to true if you want the ImageView to adjust its bounds to preserve the aspect ratio of its drawable.
<ImageView
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:adjustViewBounds="true"
android:scaleType="fitXY"/>
or try to set programatically
imageView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT));
imageView.setScaleType(ImageView.ScaleType.FIT_XY);
imageView.setAdjustViewBounds(true);
Upvotes: 1
Reputation: 1087
Use adjustViewBounds=true property in ImageView tag like
<ImageView
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:srcCompat="@drawable/background"
android:adjustViewBounds="true"
android:scaleType="fitXY"/>
Upvotes: 3