Reputation: 1
Consider the following layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TimePicker
android:layout_width="match_parent"
android:layout_height="match_parent"
android:timePickerMode="spinner" />
</LinearLayout>
TimePicker
is placed on the top of the screen, I want to vertically center it.
For example, with TextView
I would add android:gravity="center"
, but it doesn't work for TimePicker
.
Is there any way to do it?
Upvotes: -1
Views: 340
Reputation: 40888
You need to make the width & height of the TimePicker
as wrap_content
in order to center it within the LinearLayout
with android:gravity="center"
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical">
<TimePicker
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:timePickerMode="spinner" />
</LinearLayout>
Upvotes: 2