2

我想制作一个具有如下界面的应用程序,如google+或evernote,如何执行这些ui?在 Android 中使用 GridView?

4

2 回答 2

0
public class Dashboard extends Activity
    implements OnItemClickListener {
Context con;
static LauncherIcon[] ICONS = {
        new LauncherIcon(R.drawable.breakfasdd, "text1"),
        new LauncherIcon(R.drawable.lunch, "text2"),
        new LauncherIcon(R.drawable.dinner1, "text3"),
        new LauncherIcon(R.drawable.syn1, "text4"),

};

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.dashboard);
    GridView gridview = (GridView) findViewById(R.id.dashboard_grid);
    gridview.setAdapter(new ImageAdapter(this));
    gridview.setOnItemClickListener(this);
    }

static class LauncherIcon {
    final String text;
    final int imgId;

    public LauncherIcon(int imgId, String text) {
        super();
        this.imgId = imgId;
        this.text = text;
    }

}

static class ImageAdapter extends BaseAdapter {
    private Context mContext;

    public ImageAdapter(Context c) {
        mContext = c;
    }

    @Override
    public int getCount() {
        return ICONS.length;
    }

    @Override
    public LauncherIcon getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    static class ViewHolder {
        public ImageView icon;
        public TextView text;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View v = convertView;
        ViewHolder holder;
        if (v == null) {
            LayoutInflater vi = (LayoutInflater) mContext
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

            v = vi.inflate(R.layout.dashboard_icon, null);
            holder = new ViewHolder();
            holder.text = (TextView) v
                    .findViewById(R.id.dashboard_icon_text);
            holder.icon = (ImageView) v
                    .findViewById(R.id.dashboard_icon_img);
            v.setTag(holder);
        } else {
            holder = (ViewHolder) v.getTag();
        }

        holder.icon.setImageResource(ICONS[position].imgId);
        holder.text.setText(ICONS[position].text);

        return v;

    }
}

并选择项目

    @Override
    public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
        int pos = position;{
}

仪表板图标.xml

<?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" >

    <ImageView
        android:id="@+id/dashboard_icon_img"
        android:layout_width="fill_parent"
        android:layout_height="96.0dip"
        android:scaleType="fitCenter" />

    <TextView
        android:id="@+id/dashboard_icon_text"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="20.0dip"
        android:layout_marginTop="2.0dip"
        android:gravity="center"
        android:textAppearance="?android:textAppearanceSmall"
        android:textColor="@android:color/black" />

</LinearLayout>

仪表板.xml

 <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
    <Button
        android:id="@+id/back"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical|center_horizontal"
        android:layout_weight="1"
        android:text="BACK" />

    <GridView
        android:id="@+id/dashboard_grid"
        style="@style/dashboard"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:listSelector="@android:color/transparent"
        android:stretchMode="columnWidth"
        android:verticalSpacing="20.0dip" />

</RelativeLayout>
于 2012-08-24T12:36:28.570 回答
0

它们与此相似。但他们有自己的术语,称为DashBoard

这是教程的链接,

仪表板..

这是一个链接,它向您解释了一些事情,

http://android-developers.blogspot.in/2010/05/twitter-for-android-closer-look-at.html

还有这个问题,之前讨论过,

Android 仪表板模式

这似乎是建议的方法,

<com.google.android.apps.iosched.ui.widget.DashboardLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">

<Button android:id="@+id/home_btn_schedule"
    style="@style/DashboardButton"
    android:text="@string/btn_schedule"
    android:drawableTop="@drawable/home_btn_schedule" />
<Button android:id="@+id/home_btn_map"
    style="@style/DashboardButton"
    android:text="@string/btn_map"
    android:drawableTop="@drawable/home_btn_map" />
<Button android:id="@+id/home_btn_sessions"
    style="@style/DashboardButton"
    android:text="@string/btn_sessions"
    android:drawableTop="@drawable/home_btn_sessions" />
<Button android:id="@+id/home_btn_starred"
    style="@style/DashboardButton"
    android:text="@string/btn_starred"
    android:drawableTop="@drawable/home_btn_starred" />
<Button android:id="@+id/home_btn_vendors"
    style="@style/DashboardButton"
    android:text="@string/btn_vendors"
    android:drawableTop="@drawable/home_btn_vendors" />
<Button android:id="@+id/home_btn_announcements"
    style="@style/DashboardButton"
    android:text="@string/btn_announcements"
    android:drawableTop="@drawable/home_btn_announcements" />

取自这里..

于 2012-08-24T12:30:39.477 回答