How to set size of colour in grid view and change it's shape to round

605 views Asked by At
package com.example.dhavalpatel.atira;

import android.content.Intent;
import android.graphics.Color;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.GridLayout;
import android.widget.GridView;
import android.widget.TableLayout;
import android.widget.Toast;


public class second extends ActionBarActivity { 
     GridView gv;  

    String[] value1=value1=new String[]{"0","1","0","1","0"};
    String imc_met;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_second);

        gv=(GridView)findViewById(R.id.gridView);

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


                View view = super.getView(position, convertView, parent);
                String value = getItem(position);
                if (value.equals("0")) {
                  view.setVisibility(View.INVISIBLE);



                } 

          else {


                    ((TextView) view).setTextColor(Color.BLUE);
                    ((TextView) view).setTextSize((float) 1);
                    view.setBackgroundColor(Color.RED);

               }
                return view;
            }

        };

        gv.setAdapter(ad);
   }

Note : I want to set hight and width of cell in grid view. I have use grid view.setcolumnwidth,view.setHeight,view.setWidth,and many more, but no effect. I would also like to define shape of cell as circle, tried some methods and function but no use.

1

There are 1 answers

0
Oleksandr On BEST ANSWER

Make your items square as explained here

@Override
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    super.onMeasure(widthMeasureSpec, widthMeasureSpec);
}

And set background of your item with Drawable

<shape 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="oval" >
    <solid android:color="#79bfea" />
</shape>