Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Margins on children of ConstraintLayout do not display?

I'm using Android's new ConstraintLayout for my app and I've been having problems having margins on elements show up. For reference I'm using the following line in my gradle file for ConstraintLayout com.android.support.constraint:constraint-layout:1.0.0-beta4. The code in my layout is below.

<android.support.constraint.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:paddingStart="@dimen/activity_horizontal_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/post_vertical_padding"
    android:paddingEnd="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingBottom="@dimen/post_vertical_padding"
    android:background="?android:attr/selectableItemBackground">

    <TextView
        style="@style/TitleText"
        android:id="@+id/post_type"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="@dimen/post_line_vertical_padding"
        android:layout_marginEnd="@dimen/post_type_horizontal_padding"
        android:layout_marginRight="@dimen/post_type_horizontal_padding"
        app:layout_constraintLeft_toRightOf="@id/poster_profile_pic"
        app:layout_constraintTop_toTopOf="parent" />

    <TextView
        android:id="@+id/poster_name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_constraintLeft_toRightOf="@id/post_type"
        app:layout_constraintBaseline_toBaselineOf="@id/post_type" />

</android.support.constraint.ConstraintLayout>
like image 385
Matias Grioni Avatar asked Dec 28 '16 01:12

Matias Grioni


People also ask

Can we use linear layout in ConstraintLayout?

You can create linear layouts now with ConstraintLayout by constraining the sides of each element with each other. The quick way of creating these layouts is to select all the views together and right click to center horizontally or vertically.

What is ConstraintLayout guideline?

A Guideline can be either horizontal or vertical: Vertical Guidelines have a width of zero and the height of their ConstraintLayout parent. Horizontal Guidelines have a height of zero and the width of their ConstraintLayout parent.

What is ConstraintLayout widget barrier?

androidx.constraintlayout.widget.Barrier. Added in 1.1. A Barrier references multiple widgets as input, and creates a virtual guideline based on the most extreme widget on the specified side. For example, a left barrier will align to the left of all the referenced views.

Why is ConstraintLayout used?

ConstraintLayout provides you the ability to completely design your UI with the drag and drop feature provided by the Android Studio design editor. It helps to improve the UI performance over other layouts. With the help of ConstraintLayout, we can control the group of widgets through a single line of code.


1 Answers

  1. If you use paddingStart, no need for paddingLeft
  2. app:layout_constraintLeft_toRightOf="@id/poster_profile_pic" there is no image view here with id poster_profile_pic
  3. android:layout_marginBottom will not work unless you include constraintBottom_toBottomOf="parent"
  4. android:layout_marginRight should be android:layout_marginLeft but in poster_name because poster_name has app:layout_constraintLeft_toRightOf="@id/post_type"
like image 57
amorenew Avatar answered Oct 18 '22 05:10

amorenew