Reputation: 7572
I have a custom dialog box which is a series of buttons, pickers and viewswitchers. I'm trying to put a textview that displays text above the setDate and setTime buttons. At the moment it displays the textview on top of the buttons.
How can i display the textview above the time and date buttons? Thanks.
>
<?xml version="1.0" encoding="UTF-8"?>
<RelativeLayout
>
> android:padding="5dip"
> android:fitsSystemWindows="true"
> android:layout_height="wrap_content"
> android:layout_width="fill_parent"
> android:id="@+id/DateTimePicker"
> xmlns:android="http://schemas.android.com/apk/res/android">
>
>
>
> <LinearLayout
>
> android:layout_height="wrap_content"
> android:layout_width="fill_parent"
> android:id="@+id/linearlayoutdatepickermessage"
> android:layout_marginTop="5dip">
>
>
> <TextView
> android:id="@+id/textviewdatetimepickermessage"
> android:layout_width="wrap_content"
> android:layout_height="wrap_content"
> android:layout_gravity="center"
>
> />
>
> </LinearLayout>
>
> <LinearLayout
>
> android:layout_height="wrap_content"
> android:layout_width="fill_parent"
> android:id="@+id/ViewSwitchButtons"
> android:layout_marginBottom="5dip">
>
>
>
> <Button
> android:layout_height="wrap_content"
> android:layout_width="0dip"
> android:id="@+id/SwitchToDate"
> android:text="Set date"
> android:enabled="false"
> android:layout_weight="1"/>
>
> <Button
> android:layout_height="wrap_content"
> android:layout_width="0dip"
> android:id="@+id/SwitchToTime"
> android:text="Set time"
> android:layout_weight="1"/>
>
> </LinearLayout>
>
> <ViewSwitcher
> android:layout_height="wrap_content"
> android:layout_width="fill_parent"
> android:id="@+id/DateTimePickerVS"
> android:layout_below="@+id/ViewSwitchButtons"
> android:outAnimation="@android:anim/fade_out"
> android:inAnimation="@android:anim/fade_in">
>
>
>
> <LinearLayout
> android:layout_height="fill_parent"
> android:layout_width="fill_parent"
> android:id="@+id/TimeLayout"
> android:fillViewport="true">
>
> <TimePicker
> android:layout_height="wrap_content"
> android:layout_width="fill_parent"
> android:id="@+id/TimePicker"
> android:layout_marginRight="5dip"
> android:layout_marginLeft="5dip"/>
>
> </LinearLayout>
>
> <LinearLayout android:layout_height="fill_parent"
> android:layout_width="fill_parent"
> android:id="@+id/DateLayout"
> android:fillViewport="true">
>
> <DatePicker
> android:layout_height="wrap_content"
> android:layout_width="fill_parent"
> android:id="@+id/DatePicker"
> android:layout_marginRight="5dip"
> android:layout_marginLeft="5dip"/>
>
> </LinearLayout>
>
> </ViewSwitcher>
>
> <LinearLayout
> android:layout_height="wrap_content"
> android:layout_width="fill_parent"
> android:id="@+id/ControlButtons"
> android:layout_below="@+id/DateTimePicker"
> android:paddingTop="185dip">
>
> <Button
> android:layout_height="wrap_content"
> android:layout_width="0dip"
> android:id="@+id/SetDateTime"
> android:text="@android:string/ok"
> android:layout_weight="1"/>
>
> <Button
> android:layout_height="wrap_content"
> android:layout_width="0dip"
> android:id="@+id/ResetDateTime"
> android:text="Reset"
> android:layout_weight="1"/>
>
> <!-- <Button
> android:layout_height="wrap_content"
> android:layout_width="0dip"
> android:id="@+id/CancelDialog"
> android:text="@android:string/cancel"
> android:layout_weight="1"/> -->
>
> </LinearLayout>
>
> </RelativeLayout>
[edit1]
[edit2]
[edit3]
<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:id="@+id/linearlayoutdatepickermessage"
android:layout_marginTop="5dip">
<TextView
android:id="@+id/textviewdatetimepickermessage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
/>
</LinearLayout>
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:id="@+id/ViewSwitchButtons"
android:layout_marginBottom="5dip"
>
<Button
android:layout_height="wrap_content"
android:layout_width="0dip"
android:id="@+id/SwitchToDate"
android:text="Set date"
android:layout_weight="1"/>
<Button
android:layout_height="wrap_content"
android:layout_width="0dip"
android:id="@+id/SwitchToTime"
android:enabled="false"
android:text="Set time"
android:layout_weight="1"/>
</LinearLayout>
<ViewSwitcher
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:id="@+id/DateTimePickerVS"
android:outAnimation="@android:anim/fade_out"
android:inAnimation="@android:anim/fade_in">
<LinearLayout
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:id="@+id/TimeLayout"
android:fillViewport="true">
<TimePicker
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:id="@+id/TimePicker"
android:layout_marginRight="5dip"
android:layout_marginLeft="5dip"/>
</LinearLayout>
<LinearLayout android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:id="@+id/DateLayout"
android:fillViewport="true">
<DatePicker
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:id="@+id/DatePicker"
android:layout_marginRight="5dip"
android:layout_marginLeft="5dip"/>
</LinearLayout>
</ViewSwitcher>
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:id="@+id/ControlButtons"
android:paddingTop="185dip">
<Button
android:layout_height="wrap_content"
android:layout_width="0dip"
android:id="@+id/SetDateTime"
android:text="@android:string/ok"
android:layout_weight="1"/>
<Button
android:layout_height="wrap_content"
android:layout_width="0dip"
android:id="@+id/ResetDateTime"
android:text="Reset"
android:layout_weight="1"/>
<!-- <Button
android:layout_height="wrap_content"
android:layout_width="0dip"
android:id="@+id/CancelDialog"
android:text="@android:string/cancel"
android:layout_weight="1"/> -->
</LinearLayout>
</LinearLayout>
Upvotes: 0
Views: 90
Reputation: 24181
in RelativeLayout
, the default paramter of positioning a View is alignParentTop = "true"
, so in your code , you didn't specify where to put the Layout
of your Buttons
( set date/set time) , so it will be placed on the top ( with the layout of TextView
msg ) . so to put your Buttons below your textView modify your xml layout like this :
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:id="@+id/ViewSwitchButtons"
android:layout_marginBottom="5dip"
android:layout_marginTop="5dip"
android:layout_marginBottom="5dip"
android:layout_below="@+id/linearlayoutdatepickermessage" <!--this will put your buttons below the textView-->
>
Upvotes: 0
Reputation: 1728
On your ViewSwitchButtons
LinearLayout, put this:
android:layout_below="@+id/linearlayoutdatepickermessage"
Okay, your Layout consists of:
If you want to use RelativeLayout, you should add:
android:layout_below="ID_LinearLayout1"
to ViewSwitcherandroid:layout_below="ID_ViewSwitcher"
to LinearLayout2android:layout_below="ID_LinearLayout2"
to LinearLayout3Or another alternative is to change your RelativeLayout
parent to LinearLayout
with android:orientation="vertical"
Upvotes: 1