I was wondering if there is a chance to align the play button as from screenshot at the center of the screen. Unfortunately, I have only succeeded in doing such with the white space that I wish to remove. The whole code sample has been attached to the question upon request. This now illustrates the area, where two blocks must be separated with a constraint layout with a required button in the center
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/ROOT"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<RelativeLayout
android:background="#f5907c"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:orientation="vertical"
android:clickable="true"
android:focusable="true">
<View
android:id="@+id/dummyViewTop"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
<TextView
android:id="@+id/top_clock"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="false"
android:gravity="center"
android:rotation="180"
android:text="@string/DEFAULT_CLOCK_VALUE"
android:textSize="90sp"
android:textColor="@color/white"
android:textStyle="bold"
/>
</RelativeLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<ImageButton
android:id="@+id/CONTROL_BUTTON_RESET"
android:layout_width="100dp"
android:layout_height="100dp"
android:background="@android:color/transparent"
android:scaleType="center"
android:src="@drawable/ic_baseline_reset_24"
android:contentDescription="@string/reset_button_desc"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
<RelativeLayout
android:background="#2e3a52"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:orientation="vertical">
<View
android:id="@+id/dummyViewBottom"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
<TextView
android:id="@+id/bottom_clock"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="@string/DEFAULT_CLOCK_VALUE"
android:textSize="90sp"
android:textColor="@color/white"
android:textStyle="bold"
/>
</RelativeLayout>
</LinearLayout>
3
Answers
Try this
this should make your button center in the middle of the screen, provided your ConstratintLayout occupies the whole screen.
Also, don’t use
ImageButton
, use anImageView
and apply a click listener to it.I will solve this in this manner by making constraint layout as the root layout. It will flatten our view hierarchy and reduces the code complexity
I suggest you to explore Constraint layout some time
you have to give a constraint properly to your button like this: