android 图表icon问题,希望解答下

 

 



输入账户,密码之后,进入像上面图片的一个界面(附件)。

请问:

1.android中如何把这么多图标放在一个界面的啊?

2.这些图标是用imageButton做出来的还是本身就是icon,把它集中放置在一个界面?

 

Main.java
[code="java"]
package com.action;

import java.util.ArrayList;
import java.util.HashMap;

import android.app.Activity;
import android.os.Bundle;
import android.widget.GridView;
import android.widget.SimpleAdapter;

public class Main extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

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

    ArrayList<HashMap<String,Object>> gridList = new ArrayList<HashMap<String, Object>>();
    HashMap<String,Object> item = new HashMap<String,Object>();
    item.put("img", R.drawable.icon);
    item.put("str", "附近KTV");
    gridList.add(item);

    item = new HashMap<String,Object>(); 
    item.put("img", R.drawable.icon);
    item.put("str", "搜索");
    gridList.add(item);

    item = new HashMap<String,Object>(); 
    item.put("img", R.drawable.icon);
    item.put("str", "签到");
    gridList.add(item);

    item = new HashMap<String,Object>(); 
    item.put("img", R.drawable.icon);
    item.put("str", "优惠券");
    gridList.add(item);

    item = new HashMap<String,Object>(); 
    item.put("img", R.drawable.icon);
    item.put("str", "KTV排行榜");
    gridList.add(item);

    item = new HashMap<String,Object>(); 
    item.put("img", R.drawable.icon);
    item.put("str", "我的收藏");
    gridList.add(item);

    item = new HashMap<String,Object>(); 
    item.put("img", R.drawable.icon);
    item.put("str", "点歌");
    gridList.add(item);

    item = new HashMap<String,Object>(); 
    item.put("img", R.drawable.icon);
    item.put("str", "我的歌库");
    gridList.add(item);

    item = new HashMap<String,Object>(); 
    item.put("img", R.drawable.icon);
    item.put("str", "歌曲排行");
    gridList.add(item);

    item = new HashMap<String,Object>(); 
    item.put("img", R.drawable.icon);
    item.put("str", "游戏");
    gridList.add(item);

    item = new HashMap<String,Object>(); 
    item.put("img", R.drawable.icon);
    item.put("str", "我的小秘");
    gridList.add(item);

    SimpleAdapter gridAdapter = new SimpleAdapter(this, gridList, R.layout.grid_item, 
            new String[]{"img","str"}, new int[]{R.id.itemImage,R.id.itemText});
    gv.setAdapter(gridAdapter);
}

}
[/code]
main.xml
[code="xml"]
<?xml version="1.0" encoding="utf-8"?>
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
android:id="@+id/gridview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:columnWidth="90dp"
android:numColumns="auto_fit"
android:verticalSpacing="10dp"
android:horizontalSpacing="10dp"
android:stretchMode="columnWidth"
android:gravity="center"
/>

[/code]
grid_item.xml
[code="xml"]
<?xml version="1.0" encoding="utf-8"?>
android:layout_height="wrap_content" android:paddingBottom="4dip"
android:layout_width="fill_parent">
android:id="@+id/itemImage"
android:layout_width="wrap_content"
android:layout_centerHorizontal="true"
android:src="@drawable/icon" />
android:layout_below="@+id/itemImage"
android:layout_height="wrap_content"
android:text="TextView01"
android:layout_centerHorizontal="true"
android:id="@+id/itemText" />

[/code]
不会再问我

请问一下这位哥们。你是刚接触android吗?我没有搞android开发。可能我讲的不对。至于你讲的android中如何把这么多图标放在一个界面的啊、 我觉得应该有个布局之类的控件之类的。就像Swing那样的布局图标其实也可以放图片

就直接一张图片取坐标不行么?

这些图片都是事先做好后,按照相应的坐标排列。
所有的图片都配置在一个android的布局文件中,也就是一个xml文件。
一个activity也就是一个界面会读取这个xml,然后显示出整个布局文件的东西了。
布局可以是绝对的也可以是相对的。
如果你搞过android的开发就知道了。
他们可以放到Button的背景上,也可以放在ImageButton的背景。至于你说的icon设置应该是不可能。你可以对整个application设置一个icon,但里面的所有都属于这个application的内容了,我想不能在设置icon了。

采用表格布局就行了,与其它布局方法一样的。
[code="xml"]
<?xml version="1.0" encoding="utf-8"?>

android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:stretchColumns="0,2"
android:background="@drawable/back">


android:layout_column="1"
android:background="@drawable/smiley_button_states"
android:scaleType="center"
android:padding="5dip"
android:layout_width="48px"
android:layout_height="48px"/>
....

....

[/code]

可以参考GridView 的用法。

是一些图片的

你可以把这些个图片用网格布局的方式 整齐的放在一起啊

一般采用GridView即可实现此效果