Silverstorm
Silverstorm

Reputation: 15845

GridView Layout text fill issue and empty cells

I have a GridView and the text cells fills always vertically, in addition for some strange reason the attribute Refer, that could be RDA or AI, is showed only if is RDA, AI seems invisible (my table in the column Refer hasn't empty cells).

See this screenshot for better understanding enter image description here

the GridView is populated with this method

private void populateGrid(){
    Cursor c = dba.getNutriData():
    startManagingCursor(c);

    String[] from = new String[] { dba.Nutrient, dba.Intake, dba.Limit, dba.Refer};
    int[]   to = new int[] { R.id.txtNutrient, R.id.txtIntake, R.id.txtLimit, R.id.txtRefer};

    SimpleCursorAdapter sca = new SimpleCursorAdapter(this, R.layout.grid_row, c, from, to);

    grid.setAdapter(sca);
}

I use this GridView Layout

       <GridView
            android:id="@+id/tabellaDieta"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:fitsSystemWindows="false"
            android:gravity="start"
            android:numColumns="1"
            android:scrollingCache="true"
            android:stretchMode="columnWidth"
            android:textAlignment="textStart" >

        </GridView>

And this is the gridrow layout

<?xml version="1.0" encoding="utf-8"?>

<TableLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  >
  <TableRow android:layout_gravity="left">

  <TextView
      android:id="@+id/colNome"
      android:layout_width="50px"
      android:layout_height="wrap_content"
      android:layout_gravity="left"
      android:layout_weight="1"
      android:gravity="left|start"
      android:padding="5px"
      android:textColor="@color/white"
      android:textSize="12dp" />

  <TextView
      android:id="@+id/colDose"
      android:layout_width="50px"
      android:layout_height="wrap_content"
      android:layout_gravity="left"
      android:layout_weight="1"
      android:gravity="left|start"
      android:padding="5px"
      android:textColor="@color/greenlight"
      android:textSize="12dp" >

</TextView>

  <TextView
      android:id="@+id/colLimite"
      android:layout_width="50px"
      android:layout_height="wrap_content"
      android:layout_gravity="left"
      android:layout_weight="1"
      android:gravity="left|start"
      android:padding="5px"
      android:textColor="@color/orange"
      android:textSize="12dp" />

  <TextView
      android:id="@+id/colRiferimento"
      android:layout_width="50px"
      android:layout_height="wrap_content"
      android:layout_gravity="left"
      android:layout_weight="1"
      android:gravity="left|start"
      android:padding="5px"
      android:textColor="@color/light_sky"
      android:textSize="12dp" >

</TextView>

  </TableRow>
</TableLayout>

Upvotes: 3

Views: 1480

Answers (1)

Ali Imran
Ali Imran

Reputation: 9217

The value of this android:layout_weight="1" and this line android:padding="5px" and this line android:numColumns="1" are critical.

test it by removing the weight and padding line and increase the number of columns

also you have fixed the width of textView here android:layout_width="50px" make it to WrapContent

Upvotes: 4

Related Questions