http://upload.lsforum.net/users/public/h10504testj63.jpg
我想在我的应用程序的主菜单上显示11个图标,但现在我遇到了麻烦。 在第1行,Item3太长,因此第2行为显示Item3提供了一些位置。 在第2行,Item4也太长,但第3行没有为显示Item4提供一些位置。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<GridView
android:id="@+id/MenuItemGrid"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:stretchMode="spacingWidthUniform"
android:columnWidth="88dp"
android:gravity="center"
android:layout_gravity="center"
android:numColumns="3" />
</LinearLayout>
public class MainActivity extends Activity {
private int[] ItemImage = { R.drawable.ic_launcher, R.drawable.ic_launcher, R.drawable.ic_launcher,
R.drawable.ic_launcher, R.drawable.ic_launcher, R.drawable.ic_launcher,
R.drawable.ic_launcher, R.drawable.ic_launcher, R.drawable.ic_launcher,
R.drawable.ic_launcher ,R.drawable.ic_launcher };
private String[] ItemText = { "Test Long Item 1", "Test Long Item 2", "Test Long Item 333333333333",
"Test Long Item 4444444444444", "Test Long Item 5", "Test Long Item 6",
"Test Long Item 7", "Test Long Item 8", "Test Long Item 9",
"Test Long Item 10", "Test Long Item 11"};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
GridView MenuItemGrid = (GridView) findViewById(R.id.MenuItemGrid);
ArrayList<HashMap<String, Object>> ItemList = new ArrayList<HashMap<String, Object>>();
for (int i = 0; i < ItemImage.length; i++) {
HashMap<String, Object> ItemMap = new HashMap<String, Object>();
ItemMap.put("ItemImage", ItemImage[i]);
ItemMap.put("ItemText", ItemText[i]);
ItemList.add(ItemMap);
}
SimpleAdapter simpleAdapter = new SimpleAdapter(this, ItemList,
R.layout.items, new String[] { "ItemImage", "ItemText" }, new int[] {
R.id.image, R.id.title });
MenuItemGrid.setAdapter(simpleAdapter);
}
}
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:orientation="vertical" >
<ImageView
android:id="@+id/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true" />
<TextView
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/image"
android:gravity="center_horizontal"
android:layout_centerHorizontal="true" />
</LinearLayout>
答案 0 :(得分:0)
使用android:stretchMode =“columnWidth”