I'm new to the android world and this problem has been giving me headaches. I have a gridview with 4 buttons and I'd like to split the screen into 4 equal height and width buttons. (Without assigning custom dp) . I Tried to use layout_weight but it didn't work for me :/ Here is some example of my code. This is the class where I'm using the gridview
public class DietAdminPanel extends Activity {
private Button mydiets_button;
private ArrayList<String> data;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.gridview_layout);
data = new ArrayList<String>();
data.add("Test1");
data.add("Test2");
data.add("Test3");
data.add("Test4");
Log.d("On create", "success");
GridView gridview = (GridView)findViewById(R.id.gridview);
gridview.setAdapter(new GridViewAdapter(this, data));
gridview_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/gridview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:columnWidth="30dp"
android:numColumns="2"
android:verticalSpacing="0dp"
android:horizontalSpacing="0dp"
android:stretchMode="columnWidth"
android:fillViewport="true"
>
</GridView>
and gridview_item_layout.xml ( for the custom adapter)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView android:id="@+id/gridview_textview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="test"/>
</LinearLayout>
Here is how it actually looks like
https://i.stack.imgur.com/Iah2y.jpg
This is how i want my gridview to look like ( I used width in dp for this, and thats not what i want :/ )
https://i.stack.imgur.com/xHgkj.jpg
If you know something please tell me ;)