实施仪表板UI模式最有效的方法? [英] Most efficient way to implement Dashboard UI pattern?

查看:202
本文介绍了实施仪表板UI模式最有效的方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要做的仪表板模式。我目前做到这一点每个家庭按钮:

I want to do the Dashboard pattern. I currently do this for each home button:

<FrameLayout
    android:layout_weight="1"
    android:focusable="true"
    android:onClick="onHomeButtonClicked"
    android:background="@drawable/button_background">
    <TextView
        android:text="@string/button_text"
        android:drawableTop="@drawable/button_icon"
        android:layout_gravity="center"
        android:gravity="center"
        android:background="@android:color/transparent" />
</FrameLayout>

我包扎的FrameLayout里面我的按钮的原因是我想:

The reason I wrap my button inside a FrameLayout is I want to:


  • 最大化可点击区域

  • 请图标和文本正确
    居中。

我试过在过去这样做,但放弃了,因为我无法找出围绕文本和图标的屏幕大小无关的方式:

I tried doing this in the past but gave up because I couldn't figure out a screensize-independent way of centering the text and icon:

<Button
    android:layout_weight="1"
    android:background="@drawable/button_background"
    android:text="@string/button_text"
    android:onClick="onHomeButtonClicked"
    android:drawableTop="@drawable/button_icon"
    android:drawablePadding="DONT_KNOW_WHAT_TO_PUT_IN_HERE" />

我的问题:是否有可能做这些:

My question: Is it possible to do all these:


  1. 不换行内的其他按钮
    布局(使用每个只有1视图
    按钮)

  2. 最大化可点击区域

  3. 正确居中的图标和文字
    一个屏幕大小无关的方式

非常感谢。

推荐答案

下面是我用编程方式来构建一个仪表盘有些code:

Here's some code that I use to build a dashboard programmatically:

@Override public View getView(int position, View convertView,
        ViewGroup parent) {
    TextView v = (TextView) convertView;
    if (v == null) {
        v = new TextView(DashboardActivity.this);
        v.setGravity(Gravity.CENTER);
    }
    v.setCompoundDrawablesWithIntrinsicBounds(0,
        mIcons[position].drawableId, 0, 0);
    v.setText(mIcons[position].labelId);

    return v;
}

您可以改为使用Android:drawableTop在一个XML文件,如果你能事先建立的仪表盘

You could instead use android:drawableTop in an XML file if you could build the dashboard beforehand.

这篇关于实施仪表板UI模式最有效的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆