【问题标题】:How to create android app home screen with 4 icons? [closed]如何创建带有 4 个图标的 android 应用主屏幕? [关闭]
【发布时间】:2016-04-06 10:21:04
【问题描述】:

我有 4 个图标。我想创建 4 个带有图标的矩形。我还想在图标下方添加文字。我应该使用哪些组件?如何实施? 我尝试了 GridLayout 和 TableLayout 但我不知道该怎么做。 我想使用材料设计设计原生应用程序。

我在 Photoshop 中设计了演示仪表板。我的应用主屏幕应如下所示

请帮忙!我是安卓初学者。

【问题讨论】:

    标签: android android-layout material-design grid-layout dashboard


    【解决方案1】:

    已编辑试试这个代码...

    <?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"
        >
    
    
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="0.5">
    
            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:gravity="center"
                android:background="@android:color/darker_gray"
                android:layout_weight="0.5">
    
            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@mipmap/ic_launcher"
                android:layout_weight="0.5"/>
                </LinearLayout>
    
            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:gravity="center"
                android:background="@android:color/black"
                android:layout_weight="0.5">
    
                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:src="@mipmap/ic_launcher"
                    android:layout_weight="0.5"/>
            </LinearLayout>
    
        </LinearLayout>
    
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="0.5">
            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:gravity="center"
                android:background="@android:color/black"
                android:layout_weight="0.5">
    
                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:src="@mipmap/ic_launcher"
                    android:layout_weight="0.5"/>
            </LinearLayout>
    
            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:gravity="center"
                android:background="@android:color/darker_gray"
                android:layout_weight="0.5">
    
                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:src="@mipmap/ic_launcher"
                    android:layout_weight="0.5"/>
            </LinearLayout>
        </LinearLayout>
    </LinearLayout>
    

    【讨论】:

    • 谢谢。它正在工作,但我怎样才能给背景颜色(矩形)?我的图标是圆形的。
    • 请检查已编辑的答案...
    【解决方案2】:

    您可以通过以下步骤简单地通过 LinearLayout 完成上述任务 1.将布局垂直分为四部分(图像的第一和第三部分,文本的第二和第四部分) 2.将每个垂直部分分成2个水平部分。

    我已经使用对我来说完美的相同任务完成了类似的任务。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-09-25
      • 2015-12-03
      • 1970-01-01
      • 2013-10-09
      • 2011-07-10
      • 2014-09-18
      • 1970-01-01
      • 2011-09-08
      相关资源
      最近更新 更多