考虑以下布局:
<?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
位于屏幕顶部,我想将其垂直居中。
例如,对于TextView
,我将添加android:gravity="center"
,但它不适用于TimePicker
。
有办法吗?
你需要设置width &TimePicker
的高度设置为wrap_content
,以便将LinearLayout
与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>