2013-07-18 37 views
0

内我有一个自定义对话框,这是一系列的按钮,采摘和viewswitchers。我试图把显示上方的setDate和时刻设定按钮的文字一个TextView。目前它在按钮上方显示文本视图。正确放置一个TextView布局

我怎样才能显示上述时间和日期按钮TextView的?谢谢。

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中使用填充,其有效成功地将您的布局中的TextView或按钮。 – 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家长LinearLayoutandroid:orientation="vertical"

+0

由于已经做到了。然而,减号按钮现在被复位和确定按钮覆盖。我编辑了该问题以显示屏幕截图 – turtleboy

+0

您在LinearLayout和ViewSwitcher上给出了错误的名称。在你的LinearLayout上放置'android:layout_below =“@ + id/linearlayoutdatepickermessage”'并在你的ViewSwitcher上放上'android:layout_below =“YOUR_CORRECTED_ID_OF_LinearLayout”' – Aprian

+0

关键是:默认情况下,在RelativeLayout中的View是AlignParentLeft和AlignParentTop。如果您的布局流程是从上到下,请考虑使用以orientation =“vertical”作为父级的LinearLayout。 – Aprian

0
RelativeLayout

,定位示意图的默认放慢参数是alignParentTop = "true",所以在你的代码,你没有指定在哪里把你的Buttons(设定的日期/时间设置)的Layout,所以它会被放置在顶部(与TextView味精的布局)。所以把你的按钮你的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--> 
> 
相关问题