Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Any way to set barrier at a distance constraint layout or adding margin to a view the side with no constraint?

To set a background to a group of views in constraint layout, the idea is to create a View item and constraint it to the boundaries of the extreme views. But incase a group is only dependent on the right-side constraint, there is no way to add margin to the left side, hence the group of views to which a background is likely to be set, gets no left padding,

<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto">
    <data>
        <import type="android.view.View"/>
        <variable
            name="audio"
            type="example.model.observables.AttachmentObservableModel"/>
    </data>

    <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:layout_marginBottom="10dp"
        android:background="@drawable/selector_chat_row"
        >

        <include
            android:id="@+id/message_preview_layout"
            layout="@layout/reply_preview_layout"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:minWidth="160dp"
            android:layout_marginLeft="10dp"
            app:layout_constraintRight_toLeftOf="@+id/guideline"

            app:layout_constraintTop_toTopOf="parent" />

        <android.support.constraint.Barrier
            android:id="@+id/left_barrier"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            app:barrierDirection="left"
            app:constraint_referenced_ids="play_pause,message_preview_layout" />

        <View
            android:id="@+id/view"
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:background="@drawable/chat_me_background"
            app:layout_constraintBottom_toBottomOf="@+id/play_pause"
            app:layout_constraintLeft_toLeftOf="@+id/left_barrier"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

        <ImageButton
            android:id="@+id/play_pause"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:layout_marginTop="10dp"
            android:layout_marginRight="10dp"
            android:layout_marginBottom="10dp"
            android:background="@null"
            android:enabled="@{!(audio.filePath == null || audio.filePath.isEmpty())}"
            android:onClick="@{() -> audio.playing? audio.onPausePressed(): audio.onPlayPressed()}"
            android:paddingLeft="10dp"
            android:paddingBottom="10dp"
            android:src="@{audio.playing? @drawable/ic_pause_circle_filled: @drawable/ic_play_arrow}"
            app:layout_constraintRight_toLeftOf="@+id/seekbar"
            app:layout_constraintTop_toBottomOf="@+id/message_preview_layout" />

        <android.support.v7.widget.AppCompatSeekBar
            android:id="@+id/seekbar"
            android:layout_width="170dp"
            android:layout_height="wrap_content"
            android:layout_marginRight="10dp"
            android:enabled="@{!(audio.filePath == null || audio.filePath.isEmpty() || !audio.playing)}"
            android:max="@{audio.max}"
            android:onProgressChanged="@{audio::onProgressChanged}"
            android:paddingStart="10dp"
            android:paddingRight="10dp"
            android:paddingBottom="10dp"
            android:progress="@{audio.progress}"
            android:progressTint="@color/selected"
            android:secondaryProgressTint="@color/colorAccent"
            android:thumbTint="@color/colorWhite"
            app:layout_constraintBottom_toBottomOf="@+id/play_pause"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toTopOf="@+id/play_pause" />

        <ProgressBar

            android:id="@+id/progress"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:indeterminateTint="@color/color_offline"
            android:visibility="@{(audio.filePath == null ||audio.filePath.isEmpty())? View.VISIBLE:View.GONE}"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintLeft_toLeftOf="@+id/play_pause"
            app:layout_constraintRight_toRightOf="@+id/seekbar"
            app:layout_constraintTop_toTopOf="parent"
            style="?android:attr/progressBarStyleSmall"/>

        <android.support.constraint.Guideline
            android:id="@+id/guideline"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            app:layout_constraintGuide_end="15dp"
            />

    </android.support.constraint.ConstraintLayout>
</layout>

Here I want some padding on left side, where "view" is the background of all the views, but the top Constraint layout has a different background. Currently it's looking like this enter image description here

like image 672
Debanjan Avatar asked Jun 11 '18 09:06

Debanjan


1 Answers

Found the solution.

Add an empty view to the left of barrier, with width as desired padding.

<View
            android:id="@+id/left_view"
            android:layout_width="15dp"
            android:layout_height="1dp"
            app:layout_constraintRight_toLeftOf="@+id/left_barrier"/>

Now set the background view's left as this view's left. i.e change

<View
            android:id="@+id/view"
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:background="@drawable/chat_me_background"
            app:layout_constraintBottom_toBottomOf="@+id/play_pause"
            app:layout_constraintLeft_toLeftOf="@+id/left_barrier"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

to

<View
            android:id="@+id/view"
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:background="@drawable/chat_me_background"
            app:layout_constraintBottom_toBottomOf="@+id/play_pause"
            app:layout_constraintLeft_toLeftOf="@+id/left_view"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toTopOf="parent" />
like image 130
Debanjan Avatar answered Oct 15 '22 09:10

Debanjan