Adjust ConstraintLayout

1

I'm trying to fit a layout using the new ConstraintLayout , but I'm not getting it, could you give me a help? below is my layout:

<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"
tools:context="com.pdibar.pdibarlio.frags.VendaFragment"
tools:layout_editor_absoluteY="81dp">


<EditText
    android:id="@+id/edProdutoCarrinho"
    android:layout_width="368dp"
    android:layout_height="wrap_content"
    android:layout_marginEnd="8dp"
    android:layout_marginStart="8dp"
    android:layout_marginTop="8dp"
    android:layout_weight="1"
    android:drawableRight="@drawable/busca"
    android:ems="10"
    android:hint="Selecione o produto..."
    android:inputType="textPersonName"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

<TextView
    android:id="@+id/lbValorItemCarrinho"
    android:layout_width="180sp"
    android:layout_height="wrap_content"
    android:layout_marginStart="8dp"
    android:layout_marginTop="8dp"
    android:layout_weight="1"
    android:text="R$ 0,00"
    android:textColor="@color/colorPrimaryDark"
    android:textSize="30sp"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/edProdutoCarrinho" />

<EditText
    android:id="@+id/edQntItemCarrinho"
    android:layout_width="80sp"
    android:layout_height="wrap_content"
    android:layout_marginStart="8dp"
    android:layout_marginTop="8dp"
    android:layout_weight="1"
    android:ems="10"
    android:inputType="number"
    android:selectAllOnFocus="true"
    android:text="1"
    android:textAlignment="center"
    android:textSize="18sp"
    app:layout_constraintStart_toEndOf="@+id/lbValorItemCarrinho"
    app:layout_constraintTop_toBottomOf="@+id/edProdutoCarrinho" />

<Button
    android:id="@+id/btAddItemCarrinho"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_marginEnd="8dp"
    android:layout_marginStart="8dp"
    android:layout_marginTop="8dp"
    android:background="@color/colorPrimary"
    android:text="Adicionar"
    android:textColor="@android:color/white"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toEndOf="@+id/edQntItemCarrinho"
    app:layout_constraintTop_toBottomOf="@+id/edProdutoCarrinho" />


<ListView
    android:id="@+id/lvCarrinho"
    android:layout_width="0dp"
    android:layout_height="0dp"
    android:layout_marginBottom="8dp"
    android:layout_marginEnd="8dp"
    android:layout_marginStart="8dp"
    android:divider="@drawable/list_driver"
    android:dividerHeight="1sp"
    app:layout_constraintBottom_toTopOf="@+id/btFechaCarrinho"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/lbValorItemCarrinho" />

<TextView
    android:id="@+id/textView5"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_marginBottom="8dp"
    android:layout_marginStart="8dp"
    android:text="Itens"
    app:layout_constraintBottom_toTopOf="@+id/lbQntItensCarrinho"
    app:layout_constraintStart_toStartOf="parent" />

<TextView
    android:id="@+id/lbQntItensCarrinho"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginBottom="8dp"
    android:layout_marginStart="8dp"
    android:text="0000"
    android:textSize="26sp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintStart_toStartOf="parent" />

<TextView
    android:id="@+id/textView7"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_marginBottom="8dp"
    android:layout_marginStart="8dp"
    android:text="Total"
    app:layout_constraintBottom_toTopOf="@+id/lbTotalCarrinho"
    app:layout_constraintStart_toEndOf="@+id/lbQntItensCarrinho" />

<TextView
    android:id="@+id/lbTotalCarrinho"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginBottom="8dp"
    android:layout_marginStart="8dp"
    android:text="R$ 0,00"
    android:textSize="26sp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintStart_toEndOf="@+id/lbQntItensCarrinho" />

<Button
    android:id="@+id/btFechaCarrinho"
    android:layout_width="wrap_content"
    android:layout_height="48dp"
    android:layout_marginBottom="8dp"
    android:layout_marginEnd="8dp"
    android:background="@android:color/holo_green_dark"
    android:text="Fechar"
    android:textColor="@android:color/white"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent" />

</android.support.constraint.ConstraintLayout>

I want the total items, the total value and the close button, always to be at the end and according to the image, they are like this, even though items in listview , and listview are not appearing ...

    
asked by anonymous 28.03.2018 / 19:55

1 answer

2

When you are using ConstraintLayout you define wherever your component gets linked, ie what the position reference is for it.

You can set using the Android Studio properties sidebox as this image:

InthiscasethetxtTitlecomponentislinkedtothetopofActivitywithadistancebetweenthemofsize16dp.Youcanseeonthebluesidewherearetheconstraintsthatdefinethepositionofit.

Ifyoumanuallypositionandthengotothismagicwandontopofthescreenitautomaticallycreatesthosesettingsbasedontheplacementyouset.

Viacode,youcandousingtheoptionsinlayout_constraint...(hereareseveralanddependsonwhatyouwillwant.ThetextViewimagecodelookslikethis:

<TextViewandroid:id="@+id/txtTitulo"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="16dp"
            android:text="@string/cadastrar_pat"
            android:textAlignment="center"
            android:textColor="@color/viewfinder_laser"
            android:textSize="18sp"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />
    
15.05.2018 / 19:21