How to customize the layout of the main menu in Android?

For the application that I create, I plan to have a main menu consisting of 6 different icons, 2 for each line. This is very similar to the layout of the Twitter main menu, which can be seen here: nothx

So basically ... how do I customize XML? LinearLayout, TableLayout? And then, what am I actually doing so that the icons and text are evenly distributed and such? I have tried everything that I can think of and to no avail.

+7
java android xml twitter
source share
1 answer

Yes use GridView and TextView (with CompoundDrawables). I have done this before:

main.xml:

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <GridView android:id="@+id/grid" android:numColumns="2" android:horizontalSpacing="20dip" android:verticalSpacing="20dip" android:stretchMode="columnWidth" android:layout_width="fill_parent" android:layout_height="fill_parent" /> </LinearLayout> 

MainActivity:

 GridView grid = (GridView) findViewById(R.id.grid); grid.setAdapter(new HomeScreenShortcutAdapter()); grid.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View v, int position, long id) { startActivity(i); // Specify activity through Intent i } }); public class HomeScreenShortcutAdapter extends BaseAdapter { HomeScreenShortcutAdapter() { } @Override public int getCount() { return 0; } @Override public Object getItem(int position) { return null; } @Override public long getItemId(int position) { return 0; } @Override public View getView(int position, View convertView, ViewGroup parent) { TextView tv; final Object data = getItem(position); if (convertView == null) { tv = new TextView(getApplicationContext()); tv.setGravity(Gravity.CENTER); } else { tv = (TextView) convertView; } Drawable icon = data.icon; CharSequence title = data.title; tv.setCompoundDrawablesWithIntrinsicBounds( null, icon, null, null); tv.setText(title); tv.setTag(data); return tv; } } 
+7
source share

All Articles