1

I am developing an app for mobile phone, in that I needed one date & time picker, and since android does not provide both I created my custom one. but when I am adding both date picker and time picker, time picker is cutting. I don't know why. Although its running fine on tablet (as I tried it), but on phone its cutting for obvious reason. Can any body help me.

This is what I am getting.My Image

My code is

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:padding="5dp" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:orientation="horizontal" >
        <DatePicker
            android:id="@+id/dp_date"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal" />
        <TimePicker
            android:id="@+id/tp_time"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >
        <Button
            android:id="@+id/btn_date_time_ok"
            style="@style/Text.Medium"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:layout_weight="1"
            android:text="@string/ok" />
        <Button
            android:id="@+id/btn_date_time_cancel"
            style="@style/Text.Medium"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:layout_weight="1"
            android:text="@string/cancel" />
    </LinearLayout>

</LinearLayout>

Can any one suggest me something that it both picker adjust itself to screen. O r am I missing something. Any help will be appreciated. Thanks in advance.

EDIT

Is there some way to reduce the size of text used in date and time picker????

Android
  • 3,828
  • 9
  • 46
  • 79

4 Answers4

0

Try this :

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center_horizontal"
    android:orientation="horizontal"
    android:weightSum="10" >

    <DatePicker
        android:id="@+id/dp_date"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:layout_weight="5" />

    <TimePicker
        android:id="@+id/tp_time"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:layout_weight="5" />
</LinearLayout>

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >

    <Button
        android:id="@+id/btn_date_time_ok"
        style="@style/Text.Medium"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical"
        android:text="@string/ok" />

    <Button
        android:id="@+id/btn_date_time_cancel"
        style="@style/Text.Medium"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical"
        android:text="@string/cancel" />
</LinearLayout>

</LinearLayout>
Eldhose M Babu
  • 14,382
  • 8
  • 39
  • 44
0

I think you should use android:margin rather than android:padding hope it helps :)

Manoj Kumar
  • 1,510
  • 3
  • 20
  • 40
0

The problem is the size of your date and time picker. In your code the orientation of linear layout parent is set to horizontal but there is not enough space in the horizontal space. The problem might be recur even if the orientation is set to vertical.
Two way to solve this problem:

  • Use size ratio: you can assign layout_weight to the children which will maintain a size ratio and will adjust the size of the children(views) accordingly. For your requirement you can use
    layout_weight = 1 (equal size) for both the date picker and time picker.
  • Use srollView: you can use HorizontalScrollView(if orientation is horizontal) or ScrollView(if orientation is vertical). No matter how big the views are it will be taken care by these.

I hope this helps

karn
  • 5,963
  • 3
  • 22
  • 29
  • hey Thanks Karn, first one I have already tried that, but I have to try second way u suggested. Thanks for your answer – Android Aug 29 '12 at 04:37
0

Thanks for all the answers, Bu finally I resolved my problem. I am using different layout files for my phone device, so that Layout comes in proper fashion. Thanksfor all effort

Android
  • 3,828
  • 9
  • 46
  • 79