Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scaling a view reduces the content size but increases blank margins

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)

Screenshot

<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?

like image 765
AndreaF Avatar asked Apr 14 '14 21:04

AndreaF


3 Answers

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.

like image 68
Gautami Avatar answered Nov 18 '22 13:11

Gautami


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.

like image 44
starkej2 Avatar answered Nov 18 '22 13:11

starkej2


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

like image 27
user3455363 Avatar answered Nov 18 '22 15:11

user3455363