netflix spotify
netflix spotify

Reputation: 73

Constraint layout cut out some of my views

I'm using my android phone with 5'5 screen size and still cut out my

my imgView_icon and my btnConnectFacebook. I can't see them on my screen.

what's wrong then in my XML?


<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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:layout_gravity="center"
       android:background="#fff"
       tools:context="com.clearmindai.member.module.login.LoginActivity">

    <androidx.constraintlayout.widget.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="@dimen/medium"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent">

        <ImageView
                android:id="@+id/imgView_icon"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                app:layout_constraintTop_toTopOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintBottom_toTopOf="@+id/tvHeaderText"

                android:layout_marginLeft="@dimen/medium"
                android:src="@drawable/ic_login_logo"/>

        <TextView
                android:id="@+id/tvHeaderText"
                app:layout_constraintTop_toBottomOf="@+id/imgView_icon"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintBottom_toTopOf="@id/tvBodyText"
                android:layout_marginTop="@dimen/small"
                android:layout_marginLeft="@dimen/medium"
                android:textColor="@color/black"
                android:fontFamily="@font/gtwalsheimprolight"
                android:layout_width="wrap_content"
                android:textSize="@dimen/large"
                android:text="I AM THE HEADER"
                android:layout_height="wrap_content"/>

        <TextView
                android:id="@+id/tvBodyText"
                app:layout_constraintTop_toBottomOf="@+id/tvHeaderText"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintBottom_toTopOf="@id/imgViewLogo"
                android:layout_marginTop="@dimen/very_small"
                android:layout_marginLeft="@dimen/medium"
                android:text="Lorem ipmsum magic sit amendium"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"/>

        <ImageView
                android:id="@+id/imgViewLogo"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@drawable/img_login"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/tvBodyText"
                app:layout_constraintBottom_toTopOf="@+id/btnConnectFacebook"/>


        <com.facebook.login.widget.LoginButton
                android:id="@+id/btnConnectFacebook"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:paddingBottom="@dimen/small"
                android:paddingTop="@dimen/small"
                android:layout_gravity="center_horizontal"
                app:layout_constraintTop_toBottomOf="@+id/imgViewLogo"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                android:layout_marginStart="@dimen/medium"
                android:layout_marginEnd="@dimen/medium"
                app:layout_constraintStart_toStartOf="parent"/>


    </androidx.constraintlayout.widget.ConstraintLayout>


</androidx.constraintlayout.widget.ConstraintLayout>

please let me know if I need to upload the images for a better perspective of my problem.

maybe because my images are big? if my images are big how can I proportionally set a width and height for my photos where it can dynamically adjust to its parent size or screen size?

Upvotes: 2

Views: 2015

Answers (2)

Md Sufi Khan
Md Sufi Khan

Reputation: 1761

I think below solution might work for you. Remove app:layout_constraintBottom_toTopOf="@+id/tvHeaderText" from ImageView Icon

and Remove app:layout_constraintTop_toBottomOf property from all other views.

Hope it will solve your issue. :)

Upvotes: 1

Tamir Abutbul
Tamir Abutbul

Reputation: 7661

This may happen because you are using android:layout_height="wrap_content" on your imageView.

If your image is too large your layout won't be responsive anymore (because 900dp image, for example, will take all the screen size while using wrap_content).


how can i proportionally set a width and height

You can tell your image or any other view what size to be in precents like this:

 <Button
    android:id="@+id/button"
    android:layout_width="0dp"
    android:layout_height="0dp"
    app:layout_constraintWidth_percent="0.5" //50% of the screen Width
    app:layout_constraintHeight_percent="0.5" //50% of the screen Height
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

Upvotes: 1

Related Questions