Reputation: 30276
I want a layout, that the whole screen is GridView
but at the "last line" (mean bottom of the screen) will be a textview or button (to display some status). I have design this layout like the code below :
<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:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:orientation="vertical"
tools:context=".DishSelectionFragment" >
<GridView
android:id="@+id/gridView2"
android:numColumns="auto_fit"
android:gravity="center"
android:columnWidth="250dp"
android:stretchMode="columnWidth"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
</GridView>
<TextView
android:id="@+id/text_price_dish"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@+id/label"
android:layout_marginTop="2px"
android:textSize="20px" >
</TextView>
</LinearLayout>
I have tried add text to textView, but when running in emulator, the text doesn't show. I don't know how to design layout satisfied my purpose. Please help me.
Thanks :)
Upvotes: 0
Views: 301
Reputation: 1071
In GridView
change:
android:layout_height="wrap_content"
or
android:layout_above="@+id/text_price_dish"
Upvotes: 1
Reputation: 68177
You need to use RelativeLayout
as your parent layout and observe the added attributes. For example:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
enter code heretools:context=".DishSelectionFragment">
<GridView
android:id="@+id/gridView2"
android:numColumns="auto_fit"
android:gravity="center"
android:columnWidth="250dp"
android:stretchMode="columnWidth"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="@+id/text_price_dish" > <!-- added -->
</GridView>
<TextView
android:id="@+id/text_price_dish"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@+id/label"
android:layout_marginTop="2px"
android:textSize="20px"
android:layout_alignParentBottom="true" > <!-- added -->
</TextView>
</RelativeLayout>
Upvotes: 1
Reputation: 10052
You don't see TextView as GridView takes whole space android:layout_height="fill_parent"
Just change GridView as follows:
<GridView
[...]
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
/>
This will make your GridView fill all remaining space without pushing TextView out of visible area.
Upvotes: 4