问题
I am adding a DatePicker widget in my Layout.
I am using spinner type.
But a small part of widget is not visible.
I am using layout height as wrap_content
I have tried changing layout_height
attribute values but of no use.
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".StartSaving">
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
app:layout_constraintTop_toTopOf="parent">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:id="@+id/toolbar_title"
android:text="TITLE"
android:fontFamily="@font/montserratsemibold"
android:textColor="#42a5f5"
android:textSize="32sp"
android:layout_marginBottom="0dp"/>
</android.support.v7.widget.Toolbar>
<View
android:layout_width="match_parent"
android:layout_height="0.5dp"
android:id="@+id/toolbar_bottom_line"
app:layout_constraintTop_toBottomOf="@id/toolbar"
android:background="#42a5f5"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/text_branding"
android:gravity="center"
android:textColor="#20336b"
android:textSize="24sp"
android:text="TEXT 2"
android:layout_marginTop="10dp"
app:layout_constraintTop_toBottomOf="@id/toolbar_bottom_line"/>
<RadioGroup
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/radio_group"
android:paddingLeft="40dp"
android:layout_marginTop="20dp"
app:layout_constraintTop_toBottomOf="@id/text_branding"
>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:textSize="26sp"
android:text="Option 1"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:textSize="26sp"
android:text="Option 2"/>
</RadioGroup>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/enter_detail"
android:hint="Enter Detail"
android:padding="20dp"
android:inputType="number"
android:textColorHint="#42a5f5"
android:textColor="@color/title_black"
app:layout_constraintTop_toBottomOf="@id/radio_group"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@id/enter_detail"
android:id="@+id/select_date_title"
android:text="Select Date"
android:textSize="24sp"
android:textColor="@color/title_black"
android:padding="10dp"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/date"
app:layout_constraintTop_toBottomOf="@id/select_date_title"
>
<DatePicker
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:datePickerMode="spinner"
android:calendarTextColor="@color/title_black"
android:layout_marginHorizontal="15dp"
android:backgroundTint="#42a5f5"
android:background="@color/white"
android:outlineSpotShadowColor="@color/title_black">
</DatePicker>
</LinearLayout>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/save_button"
app:layout_constraintTop_toBottomOf="@id/date"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
android:text="SAVE"
android:textSize="20sp"
android:textColor="@color/white"
android:backgroundTint="#42a5f5"
android:padding="5dp"
android:layout_margin="20dp"/>
</android.support.constraint.ConstraintLayout>
This is output I get:
回答1:
Try app:layout_constraintBottom_toBottomOf="parent"
for "save_button" and for safety I would have also given app:layout_constraintBottom_toTopOf="@id/save_button"
for "date" (although it may not be required).
来源:https://stackoverflow.com/questions/54638584/android-datepicker-bottom-part-not-visbile