2013-06-02 48 views
0

我正在创建日历,并将根据当前季节制作动画。即使是冬天,雪花也会从屏幕的顶部掉下来。在屏幕上的(0,0)处绘制图像在左下角绘制

目前我的日历布局已经到位,当我在(0,0)处绘制图像时,我期望它们进入屏幕的左上角......我将我的雪花添加到主布局,但由于某些原因,他们去了我的gridView的底部。我只能假设,我的布局之一是占用空间,但我不知道.. 这里是我的日历布局:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/calendar_main_view" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@drawable/bg" 
    android:gravity="center_horizontal" 
    android:orientation="vertical" > 

    <Button android:text="Selected :" 
     android:id="@+id/main_header_image" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:background="@drawable/calendar_top_header" /> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:gravity="center_horizontal" > 

    <ImageView 
     android:id="@+id/calendar_left_arrow" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:src="@drawable/cal_left_arrow_off" /> 

    <Button android:text="" 
     android:id="@+id/selected_date" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:background="@drawable/calendar_centralheader" 
     /> 

    <ImageView 
     android:id="@+id/calendar_right_arrow" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:src="@drawable/cal_right_arrow_off" /> 

    </LinearLayout> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" > 

     <ImageView 
      android:id="@+id/imageView1" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:src="@drawable/blue_bg_with_text" /> 

    </LinearLayout> 

      <GridView 
     android:id="@+id/calendar" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:numColumns="7" > 

    </GridView> 



</LinearLayout> 

这里是一个什么样的日历看起来像Eclipse的一个截图:enter image description here

回答

1

我将我的雪花添加到主布局中,但由于某些原因他们会到我的gridView底部。

您的视图层次结构的根目录是LinearLayout,它按水平或垂直方向排列其所有子视图......没有重叠。如果您将其他视图添加到Java代码的根目录LinearLayout中,它将被添加并放置在最后一个当前子节点(这将是您的GridView)之后。

如果您要将动画季节图像添加为其他视图,您可能需要修改应用程序以在根目录处有一个FrameLayout,以便您可以添加视图并将它们简单地叠加在同一空间中(它们将固定到除非您设置了重力值)。这不会取代现有的LinearLayout,这将包括他们两个,即

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/calendar_main_view" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" > 
    <!-- Your entire existing layout now inside of here --> 
    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="@drawable/bg" 
     android:gravity="center_horizontal" 
     android:orientation="vertical" > 

     <!-- All the other existing stuff... --> 

    </LinearLayout> 
</FrameLayout> 

现在,您可以添加额外的意见,以FrameLayout,他们应该做你的期望。