Reputation: 33
I want to achieve A UI where I have Two views VIEW1, VIEW2 with these constraints
wrap_content
it's top
to be before end of VIEW1 with 10dp for example.Upvotes: 0
Views: 747
Reputation: 33
Another solution by using
a view with fixed height that equal to how many dp VIEW2 should start before end of VIEW1.
full code(also has same ending corners to bottom) ::
<?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"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/mainContent"
android:layout_width="match_parent"
android:layout_height="0dp"
android:background="@color/faded_orange"
android:text="TextView"
android:translationY="0dp"
android:textAlignment="center"
app:layout_constraintTop_toTopOf="@id/space"
app:layout_constraintBottom_toBottomOf="@id/space2"
app:layout_constraintStart_toStartOf="@id/space" />
<Space
android:id="@+id/space"
android:layout_width="match_parent"
android:layout_height="20dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintBottom_toBottomOf="@id/topLayout"
/>
<Space
android:id="@+id/space2"
android:layout_width="match_parent"
android:layout_height="20dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@id/bottomLayout"
/>
<TextView
android:id="@+id/topLayout"
android:layout_width="0dp"
android:layout_height="@dimen/_100sdp"
android:background="@drawable/header_bg"
android:text="TextView"
android:textAlignment="center"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/bottomLayout"
android:layout_width="0dp"
android:layout_height="@dimen/_100sdp"
android:background="@drawable/bg_bottom_view"
android:text="TextView"
android:textAlignment="center"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintBottom_toBottomOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
Upvotes: 1
Reputation:
As you know, setting layout_marginTop="-10dp"
will not work too.
You can try setting translationY="-10dp"
to VIEW2 then it will work.
Upvotes: 0
Reputation: 6981
As I understand you want view same as you added UI Image. This UI can be achieved using Guideline.
<?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"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/textview9"
android:layout_width="0dp"
android:layout_height="@dimen/_100sdp"
android:background="@color/bg_counter"
android:text="textview"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<androidx.constraintlayout.widget.Guideline
android:id="@+id/guideline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.13" />
<TextView
android:id="@+id/textview10"
android:layout_width="@dimen/_80sdp"
android:layout_height="0dp"
android:background="@color/colorAccent"
android:text="textview"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/guideline" />
</androidx.constraintlayout.widget.ConstraintLayout>
Upvotes: 0
Reputation: 134
You can do something like this.
Upvotes: 0