Reputation: 19854
Is it possible to set another layout as the background for a view?
What I'm looking to do is have a text view that performs a countdown behind my grid view.
I've tried setting my layout as background resource for my grid view but it seems to expect a drawable only.
What is best workaround for this? How would I go about stacking this layout behind the grid view possibly with a transparent background?
Upvotes: 1
Views: 3650
Reputation: 4180
FrameLayout can be used to stack things on top of other things.
Here is an example where I combined the HelloGridView code and my own layout of text views (that tries to emulate your counter). The result is a that the GridView displays dog pictures with the counter TextViews sort of floating above.
Hope this helps you.
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/frameLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<GridView
android:id="@+id/gridview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:columnWidth="90dp"
android:gravity="center"
android:horizontalSpacing="10dp"
android:numColumns="auto_fit"
android:stretchMode="columnWidth"
android:verticalSpacing="10dp" />
<LinearLayout
android:id="@+id/counterLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/counterLabel"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1.0"
android:gravity="center"
android:text="Counter" />
<TextView
android:id="@+id/counterValue"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1.0"
android:gravity="center"
android:text="128"
android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>
</FrameLayout>
Upvotes: 3