I am trying to get the time picker to display the full clock in landscape. The TimePicker
is in a GridLayout
. It does not overlay the screen as a DialogFragment
or a TimePickerDialog
.
Currently, this is what it shows in landscape:
As you can see, there is nothing you can pick the time with, only the default time. I am trying to get it to show the clock as well just like in portrait (which works):
The layout of the time picker:
<package.name.ScrollableTimePicker
android:id="@+id/time_picker"
android:layout_height="wrap_content"
android:layout_width="match_parent" />
The class that extends TimePicker
:
public class ScrollableTimePicker extends TimePicker {
public ScrollableTimePicker(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
public ScrollableTimePicker(Context context, AttributeSet attrs) {
super(context, attrs);
}
public ScrollableTimePicker(Context context) {
super(context);
}
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
// Keeps events to time picker
if (ev.getActionMasked() == MotionEvent.ACTION_DOWN) {
ViewParent p = getParent();
if (p != null) {
p.requestDisallowInterceptTouchEvent(true);
}
}
return false;
}
}
I looked around the internet and found these posts that did not help me:
I do not have a title for my time picker.
It has already been implemented
Tried the code in manifest but still did not work.
UPDATE As siddesh has suggested, setting layout_height
of the TimePicker
to 200dp
works but it cuts off the portrait. Now, the portrait is 200dp
tall but is cut off and the landscape is shown fully:
I had this problem too when the TimePicker was in a ScrollView, your diagnosis was helpful.
You could set the height of the TimePicker programmatically in your activity.
In onCreate() add:
TimePicker tp = (TimePicker) findViewById(R.id.time_picker);
// get display dimensions
Point p = new Point();
getWindowManager().getDefaultDisplay().getSize(p);
int newHeight;
if(p.x > p.y) {
// if landscape, convert 200dp to px
newHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 200, getResources().getDisplayMetrics());
} else {
newHeight = WindowManager.LayoutParams.WRAP_CONTENT;
}
// set TimePicker height
tp.getLayoutParams().height = newHeight;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.