I'm trying to scale a horizontal LinearLayout
that contains DatePicker
and TimePicker
adding
android:scaleX="0.6"
android:scaleY="0.6"
The problem is that this scales the content but increases the margin at the same time, so I cannot use the space properly. In the picture the marked white area is the space gained by scaling, but I cannot use this space (in fact, the clock on the right is cropped)
<LinearLayout
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:scaleX="0.6"
android:scaleY="0.6">
<DatePicker
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/datePicker"
android:layout_gravity="center_horizontal"
android:calendarViewShown="false"
android:spinnersShown="false"
android:layoutMode="opticalBounds"
android:measureAllChildren="true" />
<TimePicker
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/timePicker"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="5dp" />
</LinearLayout>
Any solution to scale the view without this blank space problem?
I would suggest you not to use xscale & yscale. Instead what you can do is provide weight for date picker & time picker.
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal">
<DatePicker
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="50"
android:id="@+id/datePicker"
android:layout_gravity="center_horizontal"
android:calendarViewShown="false"
android:spinnersShown="false"
android:layoutMode="opticalBounds"
android:measureAllChildren="true" />
<TimePicker
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="50"
android:id="@+id/timePicker"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="5dp" />
</LinearLayout>
you can add padding at sides or modify the weights as an how you want.
Are you able to use the date and time picker in a dialog instead? I think that may be your only option. I'm not aware of a way to shrink the size of the DatePicker and TimePicker the way you're trying to. See http://developer.android.com/guide/topics/ui/controls/pickers.html#DatePickerFragment.
Scalling will not change your controls size it means your data picker will take same space in your layout regardless if it is scalled up or down. only thier apperance changes
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With