Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Constraint Layout doesn't stretch on full screen

Tags:

java

android

I have a problem with layout which won't stretch within high resolution like 1920x1080. As root layout I use Constraint Layout with following style:

<android.support.constraint.ConstraintLayout 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"
android:focusable="true"
android:focusableInTouchMode="true"
tools:context="njc.nhutrinhgold.MainActivity">

<ImageView
    android:id="@+id/imgNen"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:adjustViewBounds="true"
    android:scaleType="fitXY"
    android:visibility="visible"
    app:layout_constraintDimensionRatio="16:9"
    app:srcCompat="@drawable/xxhdpibg"
    tools:layout_editor_absoluteX="0dp"
    tools:layout_editor_absoluteY="0dp"
    tools:layout_width="match_parent" />

and in Manifest.xml

<supports-screens
    android:anyDensity="true"
    android:compatibleWidthLimitDp="960"
    android:largeScreens="true"
    android:largestWidthLimitDp="960"
    android:normalScreens="false"
    android:requiresSmallestWidthDp="960"
    android:resizeable="false"
    android:smallScreens="false"
    android:xlargeScreens="true" />

I want to stretch layout to any screen resolution but on emulator with high resolution it looks like this:

enter image description here

Actually I didn't figured out what is the problem

like image 862
alongquan Avatar asked Oct 25 '25 07:10

alongquan


1 Answers

Do it like this, and tell me what are you getting, because this is the ideal way of doing this, since everybody is saying the same thing but do it like this. match_parent is generally the key

<android.support.constraint.ConstraintLayout 
 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"
 android:focusable="true"
 android:focusableInTouchMode="true"
 tools:context="njc.nhutrinhgold.MainActivity">

<ImageView
   android:id="@+id/imgNen"
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   android:scaleType="centreCrop"
   android:visibility="visible"
   app:layout_constraintDimensionRatio="16:9"
   app:srcCompat="@drawable/xxhdpibg"
   tools:layout_editor_absoluteX="0dp"
   tools:layout_editor_absoluteY="8dp"
   tools:layout_width="match_parent" />

Remove adjustViewBound and set the scaleType as centreCrop, you'll see the change

**NOTE : ** This is for the layout to take up the whole screen and adjust (stretching to the whole screen)

like image 75
Alok Avatar answered Oct 26 '25 22:10

Alok