android - Constraintlayout shows different from android studio

Asked

Viewed 27 times

-1

I made a login screen with Contraintlayout, in the editor of android studio appears with the margin as I specified, but in emulator and device appears without the margin:

inserir a descrição da imagem aqui

<?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"
    tools:context=".activities.LoginActivity">

    <ImageView
        android:id="@+id/actLogin..."
        android:layout_width="80dp"
        android:layout_height="80dp"
        android:layout_marginTop="86dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:srcCompat="@drawable/ic_...." />

    <TextView
        android:id="@+id/actLoginTv..."
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="16dp"
        android:fontFamily="sans-serif-black"
        android:text="@string/app_name"
        android:textColor="@color/colorPrimary"
        android:textSize="30sp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/actLogin..." />

    <EditText
        android:id="@+id/etActLoginEmail"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginStart="32dp"
        android:layout_marginTop="32dp"
        android:layout_marginEnd="32dp"
        android:drawableStart="@drawable/ic_email"
        android:drawablePadding="8dp"
        android:ems="10"
        android:hint="@string/email"
        android:inputType="textEmailAddress"
        android:maxLines="1"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/actLoginTv..." />

    <EditText
        android:id="@+id/etActLoginPassword"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginStart="32dp"
        android:layout_marginTop="32dp"
        android:layout_marginEnd="32dp"
        android:drawableStart="@drawable/ic_lock"
        android:drawablePadding="8dp"
        android:ems="10"
        android:hint="@string/password"
        android:inputType="textPassword"
        android:maxLength="16"
        android:maxLines="1"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/etActLoginEmail" />

    <com.google.android.material.button.MaterialButton
        android:id="@+id/btnActLoginSignUp"
        style="@style/Widget.AppCompat.Button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="24dp"
        android:layout_marginEnd="32dp"
        android:onClick="onSignUpClicked"
        android:text="@string/sign_up"
        app:backgroundTint="#FFFFFF"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/etActLoginPassword" />

    <com.google.android.material.button.MaterialButton
        android:id="@+id/btnActLoginSignIn"
        style="@style/Widget.AppCompat.Button.Colored"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="195dp"
        android:layout_marginEnd="32dp"
        android:onClick="onSignInClicked"
        android:text="@string/sign_in"
        app:layout_constraintBottom_toBottomOf="@+id/btnActLoginSignUp"
        app:layout_constraintEnd_toStartOf="@+id/btnActLoginSignUp"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="@+id/btnActLoginSignUp" />


</androidx.constraintlayout.widget.ConstraintLayout>

Why do the edges of the buttons disappear on the practice screen? Some ids I hid the name for security reasons

  • What image format are you calling in app:srcCompat="@drawable/ic_...."?

  • @julianosantos all the Assets I use in the app is SVG

1 answer

0

I have already gone through a similar situation and decided to simply change the format of the image that should be shown in Imageview. Usually svg and vectors in general always behave strangely in Imageview.So take the same image in png or jpeg format and add it to drawable and then call it in xml in the same way that Voce called svg.I think that’s enough to solve

Browser other questions tagged

You are not signed in. Login or sign up in order to post.