So I am currently using constraint layout for my signup screen. However, the signup button is supposed to be like 100dp from parent bottom, rather than 200 dp
from the top element. Whenever I try to remove the top margin and try to make it relative to the parent bottom, it ends up in almost the middle of the screen instead of the bottom. I was wondering if there's a way I can make it such that it aligns to the bottom of the screen?
Here's my code :
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/content_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/black"
android:fitsSystemWindows="true">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:foreground="@drawable/image_gradient"
android:scaleType="centerCrop"
android:src="@drawable/hero_image"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:contentDescription="@null" />
<ImageView
android:id="@+id/logo"
android:layout_width="207dp"
android:layout_height="77dp"
android:layout_gravity="center_horizontal"
android:layout_marginTop="180dp"
android:contentDescription="@string/my_logo"
android:src="@drawable/ic_my_white_logo"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<android.support.v7.widget.AppCompatButton
android:id="@+id/btn_login"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/activity_horizontal_margin"
android:layout_marginTop="200dp"
android:layout_marginRight="@dimen/activity_horizontal_margin"
android:background="@color/white"
android:fontFamily="sans-serif-medium"
android:letterSpacing="0.07"
android:lineSpacingExtra="0sp"
android:text="@string/sign_in"
android:textColor="@color/reddish"
android:textSize="16sp"
android:textStyle="normal"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintBottom_toTopOf="@id/link_sign_up"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@id/logo"
app:layout_constraintVertical_chainStyle="packed" />
<TextView
android:id="@+id/link_sign_up"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/activity_horizontal_margin"
android:layout_marginTop="15dp"
android:layout_marginRight="@dimen/activity_horizontal_margin"
android:fontFamily="sans-serif-medium"
android:gravity="center_horizontal"
android:letterSpacing="0.07"
android:lineSpacingExtra="0sp"
android:text="@string/no_account"
android:textColor="@color/white"
android:textSize="16sp"
android:textStyle="normal"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/btn_login" />
</android.support.constraint.ConstraintLayout>
From the above XML, button login_in and sign_up link are supposed to be together (which works as expected), login button, below that signup link. But I am manually setting "android:layout_marginTop="200dp"
from the logo on top of it, which is not a good practice, as for some devices, it does not end up aligning to the bottom as expected (and is hardcoded). Rather I would like it to say 100dp
from the margin with no alliance to the top, so for any device, it's 100dp
from the bottom. Any ideas on how to fix this to achieve the goal?
Thanks in advance!