0

I have 3 columns in a gridview and in every cell is a button but the first column should be thinner than the others but I'm not able to accomplish that, here the code

<?xml version="1.0" encoding="utf-8"?>
  <RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">


<Button
    android:id="@+id/cell"
    android:layout_height="12dp"
    android:layout_width="wrap_content"
    android:background="#ffffff"
    android:textColor="#000000"
    />
</RelativeLayout>

And here the java code:

  public View getView(int position, View convertView, ViewGroup parent) {

        View row = convertView;

        if (row == null) {
            LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            row = inflater.inflate(R.layout.cell, parent, false);
        }


        gridcell = (Button) row.findViewById(R.id.cell);
        String tmp = list.get(position);
        gridcell.setTextSize(10);
        gridcell.setText(tmp);          

        //first column
        if ((position % 3) == 0) {
                    gridcell.setBackgroundColor(Color.LTGRAY);
                    //width should be changed       
                    gridcell.setWidth(5);
        } else {
            gridcell.setBackgroundColor(Color.BLUE);
            gridcell.setWidth(50);
        }



        return row;     


    }

Any suggestions

wasp256
  • 5,943
  • 12
  • 72
  • 119

1 Answers1

1

Gridviews with different column widths wont work.

You should use a Listview with a LinearLayout in each Row instead.

See here: GridView with different column sizes

Community
  • 1
  • 1
Yalla T.
  • 3,707
  • 3
  • 23
  • 36