0

I'm creating a calendar and will be having animations based on the current season. i.e if it's winter, snowflakes will fall from the top of the screen.

Currently I have the calendar layout in place and when I draw my images at (0,0) I expect them to go to the top left of the screen... I'm adding my snowflake's to the main layout, but for some reason they go to the bottom of my gridView. I can only assume that one of my layouts is taking up space but I'm not sure.. Here is my calendar layout:

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

here's a screenshot of what the calendar looks like in eclipse:enter image description here

4

1 回答 1

1

I'm adding my snowflake's to the main layout, but for some reason they go to the bottom of my gridView.

The root of your view hierarchy is a LinearLayout, which lays out all of its child views in order horizontally or vertically...none of them overlap. If you add another view to your root LinearLayout in Java code, it will get added and laid out after the last current child (which would be your GridView).

If you are adding your animated season images as additional views, you likely want to modify your application to have a FrameLayout at the root so that you can add views and have them simply overlay in the same space (they will pin to the top left unless you set a gravity value). This would not replace your existing LinearLayout, it would encompass them both, i.e.

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

Now you can add your extra views to the FrameLayout and they should do what you expect.

于 2013-06-02T04:36:54.777 回答