2013-07-18 3 views
0

У меня есть настраиваемое диалоговое окно, которое представляет собой серию кнопок, сборщиков и просмотрщиков. Я пытаюсь поместить текст, который отображает текст над кнопками setDate и setTime. На данный момент он отображает текст сверху кнопок.Правильное размещение текста в макете

Как я могу отобразить текстовое изображение над кнопками времени и даты? Благодарю.

enter image description here

>

<?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] enter image description here

[edit2] enter image description here

[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> 
+0

попробуйте использовать прописку в xml, чтобы удобно разместить текст или кнопки в макетах. – harikrishnan

ответ

1

На вашем ViewSwitchButtons LinearLayout, поставить это:

android:layout_below="@+id/linearlayoutdatepickermessage" 

Хорошо, ваш макет состоит из:

  1. LinearLayout1
  2. ViewSwitcher
  3. LinearLayout2
  4. LinearLayout3

Если вы хотите использовать RelativeLayout, вы должны добавить:

  1. android:layout_below="ID_LinearLayout1" в ViewSwitcher
  2. android:layout_below="ID_ViewSwitcher" к LinearLayout2
  3. android:layout_below="ID_LinearLayout2" в LinearLayout3

Или другая альтернатива, чтобы изменить ваш RelativeLayout Родитель до LinearLayout с android:orientation="vertical"

+0

Спасибо, что сделал это. Однако кнопки минус закрываются кнопками сброса и ok. Я отредактировал вопрос, чтобы показать экранный снимок. – turtleboy

+0

Вы указали неправильное имя на LinearLayout и ViewSwitcher. На вашем LinearLayout поместите 'android: layout_below =" @ + id/linearlayoutdatepickermessage "и на ваш ViewSwitcher поместите' android: layout_below = "YOUR_CORRECTED_ID_OF_LinearLayout" ' – Aprian

+0

Дело в том, что по умолчанию View в RelativeLayout являются AlignParentLeft и AlignParentTop.Если ваш поток макета находится сверху вниз, рассмотрите возможность использования LinearLayout с ориентацией = "vertical" в качестве родителя. – Aprian

0

в RelativeLayout, по умолчанию параметра Я в позиционировании View является alignParentTop = "true", поэтому в вашем коде, вы не указали, где поставить Layout вашего Buttons (дата/заданное время), так что он будет помещен на наверх (с макетом TextView сообщений). поэтому, чтобы поместить ваши кнопки под вашим текстовым редактором, измените свой xml-макет следующим образом:

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