1

I have a GirdView of 9 TextViews. I want to make the 9 Textviews to distribute equally in the height and the width. to fit the GridView exactly. How can I do this?

This is how I add Textviews to Gridview

String[] arrayEmpty = new String[] {"", "", "", "", "", "", "", "", ""};
ArrayList<String> list = new ArrayList<String>(Arrays.asList(arrayEmpty));
gridView.setAdapter(new ArrayAdapter<String>(this,R.layout.list_item,list));

This is what I have got enter image description here

I tried to use something like gridview.layoutparams but I could not. Help me to distribute them equally like this enter image description here

I have overrided the method onMeasure, but did not work

import android.content.Context;
import android.util.AttributeSet;
import android.widget.GridView;

public class myGridView extends GridView {
public myGridView(Context context) {
    super(context);
}

public myGridView(Context context, AttributeSet attrs) {
    super(context, attrs);
}

public myGridView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
}

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

}
Sami Eltamawy
  • 9,874
  • 8
  • 48
  • 66

1 Answers1

1

Check this

Git Hub.

It's open source project in Git Hub.Here you can find layout and source code for Sudoku.I hope it will help you.

TheFlash
  • 5,997
  • 4
  • 41
  • 46
  • could you give a specific answer, it is a big project to inspect each class or layout – Sami Eltamawy May 06 '13 at 09:15
  • @Abd El-Rahman El-Tamawy check it.I have edited my answer. – TheFlash May 06 '13 at 09:21
  • I have checked it, still confused. The first project is so huge to find similar code and the second on is not in Java – Sami Eltamawy May 06 '13 at 09:28
  • 1
    @Abd El-Rahman El-Tamawy-wait..I will see if i find some useful for u. – TheFlash May 06 '13 at 09:32
  • 1
    @Abd El-Rahman El-Tamawy-Check in the project link that i have posted above res/layout/sudoku_edit.xml for Sudoku View. – TheFlash May 06 '13 at 09:46
  • I have found out that the trick is in overriding the method onMeasure for the class that extend GridView, but what I should do exactly. I don`t know....i Tried to but the hight and the width same as each other but it did not works – Sami Eltamawy May 06 '13 at 09:59
  • thank you for your help, but still have the same problem – Sami Eltamawy May 06 '13 at 10:13
  • 1
    @Abd El-Rahman El-Tamawy-I have not implemented sudoku yet so i have suggested you links..but i will try to find some more useful links only for you. – TheFlash May 06 '13 at 10:20