0

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

4

3 回答 3

4

您看不到 TextView,因为 GridView 占用了整个空间android:layout_height="fill_parent" 只需将 GridView 更改如下:

<GridView
    [...]  
    android:layout_width="fill_parent"
    android:layout_height="0dp"
    android:layout_weight="1"
/>

这将使您的 GridView 填充所有剩余空间,而不会将 TextView 推出可见区域。

于 2013-03-25T10:46:55.303 回答
1

您需要RelativeLayout用作父布局并观察添加的属性。例如:

<?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>
于 2013-03-25T10:48:42.910 回答
1

GridView变化中:

android:layout_height="wrap_content"

或者

android:layout_above="@+id/text_price_dish"       
于 2013-03-25T10:47:46.900 回答