jackhab
jackhab

Reputation: 17718

How to keep ListView on the Frame Layout bottoms

I need to place a small rectangle above ListView. I used Frame Layout to achieve it.

   item1              item1             item1
   item2              item2             item2
+----------------------------------------------+
|  item3              item3             item3  |
+----------------------------------------------+
   item4              item4             item4

Now I have a problem that each time I scroll the list it pops up hiding the the rectangle and returns to the background when I click the list again.

Is there a way to keep the rectangle always on top of the list? Are there other ways besides Frame Layout to overlay views?

Thanks.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".MainActivity" >

    <EditText
        android:id="@+id/edittextSubject"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="@dimen/activity_horizontal_margin"
        android:hint="@string/hint_remind" />

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

        <View
            android:id="@+id/rectSelectTime"
            android:layout_width="match_parent"
            android:layout_height="72dp"
            android:layout_gravity="center_vertical|center_horizontal|fill_horizontal"
            android:background="@drawable/select_rect"
            android:clickable="true"
            android:importantForAccessibility="yes" />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="@dimen/scroller_height"
            android:layout_marginBottom="@dimen/activity_horizontal_margin"
            android:baselineAligned="false"
            android:orientation="horizontal" >

            <ListView
                android:id="@+id/listviewTimeInterval"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:focusable="false"
                android:focusableInTouchMode="false"
                android:scrollbars="none"
                android:tag="TimeInterval" >
            </ListView>

            <ListView
                android:id="@+id/listviewHour"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:scrollbars="none"
                android:tag="Hour" >
            </ListView>

            <ListView
                android:id="@+id/listviewMinute"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:scrollbars="none"
                android:tag="Minute" >
            </ListView>
        </LinearLayout>
    </FrameLayout>

</LinearLayout>

Upvotes: 2

Views: 4204

Answers (1)

ruben
ruben

Reputation: 1750

Ok Here is your solved code. Now the image is always on top:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".MainActivity" >

    <EditText
        android:id="@+id/edittextSubject"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="@dimen/activity_horizontal_margin"
        android:hint="@string/app_name" />

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



        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginBottom="@dimen/activity_horizontal_margin"
            android:baselineAligned="false"
            android:orientation="horizontal" >

            <ListView
                android:id="@+id/listviewTimeInterval"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:focusable="false"
                android:focusableInTouchMode="false"
                android:scrollbars="none"
                android:tag="TimeInterval" >
            </ListView>

            <ListView
                android:id="@+id/listviewHour"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:scrollbars="none"
                android:tag="Hour" >
            </ListView>

            <ListView
                android:id="@+id/listviewMinute"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:scrollbars="none"
                android:tag="Minute" >
            </ListView>
        </LinearLayout>

        <View
            android:id="@+id/rectSelectTime"
            android:layout_width="match_parent"
            android:layout_height="72dp"
            android:layout_gravity="center_vertical|center_horizontal|fill_horizontal"
            android:background="@drawable/ic_launcher"
            android:clickable="true"
            android:importantForAccessibility="yes" />
    </FrameLayout>

</LinearLayout>

Upvotes: 1

Related Questions