wasp256
wasp256

Reputation: 6242

Android Button width in gridview

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

Upvotes: 0

Views: 471

Answers (1)

Yalla T.
Yalla T.

Reputation: 3727

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

Upvotes: 1

Related Questions