代码之家  ›  专栏  ›  技术社区  ›  Robby Pond

Android仪表板模式

  •  34
  • Robby Pond  · 技术社区  · 15 年前

    在蒂姆·布雷最新的安卓系统中 blog post 他提到了“仪表板”的用户界面模式(Twitter应用程序、Facebook应用程序等都使用了这种模式。这种布局是像带按钮的GridView那样简单,还是其他什么?

    更新:

    这个 DashboardLayout 昨晚被罗曼·努里克释放了。它是googleio2010应用程序中使用的布局的衍生产品。

    8 回复  |  直到 14 年前
        1
  •  41
  •   CiTuX David Vávra    12 年前

    http://code.google.com/p/iosched/source/browse/android/res/layout/fragment_dashboard.xml?r=27a82ff10b436da5914a3961df245ff8f66b6252

    2011版使用了一个称为“DashboardLayout”的定制布局,在手机和平板电脑特定的布局中共享。仪表板布局中的逻辑负责所有的自动布局魔术!

        2
  •  25
  •   CiTuX David Vávra    12 年前

    IO 2010应用程序的仪表板布局代码有点问题。但是Roman Nurik已经修复了它,现在可以在应用程序中轻松使用仪表板布局。

    操作方法:

    1. this class 加入你的项目
    2. like here
        3
  •  4
  •   thunsaker    15 年前

    我能够实现一个类似的仪表板使用相对布局。这项工作仍在进行中,因此您的里程数可能会有所不同。

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/lay_wrapper"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >
        <LinearLayout android:id="@+id/lay_action"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:background="#000000" >
            <TextView android:id="@+id/label_header"
                android:layout_width="wrap_content"
                android:layout_height="50px"
    
                android:text="@string/app_title"
                android:textColor="#000000"
                android:textSize="25sp"
                android:paddingLeft="10px"
                android:gravity="center_vertical"
                android:layout_gravity="center_vertical" 
                />
        </LinearLayout>
        <RelativeLayout android:id="@+id/lay_main"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" 
            android:layout_below="@id/lay_action"
            android:paddingTop="25px"
            android:layout_centerInParent="true">
    
            <Button android:id="@+id/button1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/button1"
                android:padding="25dip"
                android:drawableTop="@drawable/button1" />
    
            <Button android:id="@+id/button2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_toRightOf="@id/button1"
                android:text="@string/button2"
                android:padding="25dip"
                android:drawableTop="@drawable/button2" />
    
            <Button android:id="@+id/button3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@id/button1"
                android:text="@string/button3"
                android:padding="25dip"
                android:drawableTop="@drawable/button3" />
    
            <Button android:id="@+id/button4"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_toRightOf="@id/button3"
                android:layout_below="@id/button2"
                android:text="@string/button4"
                android:padding="25dip"
                android:drawableTop="@drawable/button4" />
        </RelativeLayout>
    </RelativeLayout>
    
        4
  •  4
  •   AlikElzin-kilaka planben    13 年前

    仪表板布局不适合我,因此我建议使用基于布局的解决方案。 只是版面中的一堆版面。

    关键是间距布局和内容布局之间权重的相关性。

    您可以非常简单地移动图标,并为更大或更轻的仪表板定义其他布局。

    下面是它的样子:

    portrait

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/dashboard"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >
    
        <FrameLayout style="@style/dashboard_space_vertical" />
    
        <LinearLayout style="@style/dashboard_content_vertical" >
    
            <FrameLayout style="@style/dashboard_space_horizontal" >
            </FrameLayout>
    
            <LinearLayout style="@style/dashboard_content_horizontal" >
    
                <ImageView
                    style="@style/dashboard_imageview"
                    android:src="@android:drawable/sym_call_missed" />
    
                <TextView
                    style="@style/dashboard_textview"
                    android:text="Text 1" />
            </LinearLayout>
    
            <FrameLayout style="@style/dashboard_space_horizontal" />
    
            <LinearLayout style="@style/dashboard_content_horizontal" >
    
                <ImageView
                    style="@style/dashboard_imageview"
                    android:src="@android:drawable/sym_call_missed" />
    
                <TextView
                    style="@style/dashboard_textview"
                    android:text="Text 2" />
            </LinearLayout>
    
            <FrameLayout style="@style/dashboard_space_horizontal" />
        </LinearLayout>
    
        <FrameLayout style="@style/dashboard_space_vertical" />
    
        <LinearLayout style="@style/dashboard_content_vertical" >
    
            <FrameLayout style="@style/dashboard_space_horizontal" />
    
            <LinearLayout style="@style/dashboard_content_horizontal" >
    
                <ImageView
                    style="@style/dashboard_imageview"
                    android:src="@android:drawable/sym_call_missed" />
    
                <TextView
                    style="@style/dashboard_textview"
                    android:text="Text 3" />
            </LinearLayout>
    
            <FrameLayout style="@style/dashboard_space_horizontal" />
    
            <LinearLayout style="@style/dashboard_content_horizontal" >
    
                <ImageView
                    style="@style/dashboard_imageview"
                    android:src="@android:drawable/sym_call_missed" />
    
                <TextView
                    style="@style/dashboard_textview"
                    android:text="Text 4" />
            </LinearLayout>
    
            <FrameLayout style="@style/dashboard_space_horizontal" />
        </LinearLayout>
    
        <FrameLayout style="@style/dashboard_space_vertical" />
    
        <LinearLayout style="@style/dashboard_content_vertical" >
    
            <FrameLayout style="@style/dashboard_space_horizontal" />
    
            <LinearLayout style="@style/dashboard_content_horizontal" >
    
                <ImageView
                    style="@style/dashboard_imageview"
                    android:src="@android:drawable/sym_call_missed" />
    
                <TextView
                    style="@style/dashboard_textview"
                    android:text="Text 5" />
            </LinearLayout>
    
            <FrameLayout style="@style/dashboard_space_horizontal" />
    
            <LinearLayout style="@style/dashboard_content_horizontal" >
    
                <ImageView
                    style="@style/dashboard_imageview"
                    android:src="@android:drawable/sym_call_missed" />
    
                <TextView
                    style="@style/dashboard_textview"
                    android:text="Text 6" />
            </LinearLayout>
    
            <FrameLayout style="@style/dashboard_space_horizontal" />
        </LinearLayout>
    
        <FrameLayout style="@style/dashboard_space_vertical" />
    
    </LinearLayout>
    

    以下是样式:

    <resources>
    <style name="dashboard_space_vertical">
        <item name="android:layout_width">fill_parent</item>
        <item name="android:layout_height">0px</item>
        <item name="android:layout_weight">1</item>
    </style>
    
    <style name="dashboard_content_vertical">
        <item name="android:layout_width">fill_parent</item>
        <item name="android:layout_height">0px</item>
        <item name="android:layout_weight">3</item>
        <item name="android:layout_gravity">center</item>
    </style>
    
    <style name="dashboard_space_horizontal">
        <item name="android:layout_width">0px</item>
        <item name="android:layout_height">fill_parent</item>
        <item name="android:layout_weight">2</item>
        <!-- <item name="android:background">@color/black</item> -->
    </style>
    
    <style name="dashboard_content_horizontal">
        <item name="android:layout_width">0px</item>
        <item name="android:layout_height">fill_parent</item>
        <item name="android:layout_weight">3</item>
        <item name="android:orientation">vertical</item>
        <item name="android:layout_gravity">center</item>
        <item name="android:gravity">center</item>
    </style>
    
    <style name="dashboard_imageview">
        <item name="android:layout_width">fill_parent</item>
        <item name="android:layout_height">fill_parent</item>
        <item name="android:layout_weight">1</item>
        <item name="android:scaleType">fitCenter</item>
    </style>
    
    <style name="dashboard_textview">
        <item name="android:layout_width">fill_parent</item>
        <item name="android:layout_height">wrap_content</item>
        <item name="android:gravity">center</item>
        <item name="android:textSize">@dimen/dashboard_thumbnail_text_size</item>
        <item name="android:textStyle">bold</item>
        <item name="android:textColor">@color/blue</item>
    </style>
    </resources>
    

    希望这对别人有帮助。好好享受。

        5
  •  2
  •   molnarm    15 年前

    能够 可以使用包含图像和文本视图的TableLayout来实现。

        6
  •  2
  •   Jitu    13 年前
        7
  •  1
  •   Macarse    14 年前

    罗曼努里克最近发布了一个 ViewGroup 做这个。代码是 here