AndreaF
AndreaF

Reputation: 12395

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?

Upvotes: 8

Views: 2018

Answers (3)

user3455363
user3455363

Reputation: 418

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

Upvotes: 1

starkej2
starkej2

Reputation: 11519

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.

Upvotes: 1

Gautami
Gautami

Reputation: 361

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.

Upvotes: 2

Related Questions