android - 如何在 Android View 下方设置高程颜色?

标签 android xml android-layout user-interface

我正在 Android Studio 中创建以下设计。但我坚持如何在高程中添加颜色,如下图所示。每个按钮下方显示绿色。我不知道我怎么能做到这一点。

design to achieve

我什至设置了

android:outlineSpotShadowColor

还有这个

android:outlineAmbientShadowColor

但是,我仍然没有实现我想要实现的目标。

这是我的布局 XML,以备不时之需。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".views.CreateActivity">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="60dp"
        android:elevation="5dp"
        android:background="@drawable/white"
        android:id="@id/rel1">

        <ImageView
            android:layout_width="50dp"
            android:layout_height="40dp"
            android:layout_centerVertical="true"
            android:src="@drawable/ic_back"
            android:id="@+id/backBut"

            />

        <TextView
            android:id="@+id/textView4"

            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:fontFamily="@font/roboto_bold"
            android:text="CREATE"
            android:textColor="#000"
            android:textSize="20sp" />


    </RelativeLayout>


    <android.support.v7.widget.CardView
        android:layout_width="match_parent"
        android:layout_height="130dp"
        android:layout_below="@id/rel1"
        android:layout_marginTop="20dp"
        android:layout_marginStart="30dp"
        android:layout_marginEnd="30dp"
        app:cardCornerRadius="15dp"
        app:cardElevation="5dp"
        android:id="@+id/createSingleDealBut"
        >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="horizontal"
            android:layout_margin="5dp"
            android:weightSum="1"
            >

            <RelativeLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="0.3"
                >
                <ImageView
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_centerInParent="true"
                    android:src="@drawable/hourglass"
                    android:scaleType="centerInside"
                    android:layout_margin="20dp"
                    />

            </RelativeLayout>
            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="0.6"
                android:orientation="vertical">

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:fontFamily="@font/roboto_medium"
                    android:layout_marginTop="20dp"
                    android:text="Single Deal"
                    android:textColor="#000"
                    android:textSize="18sp"
                    />

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:fontFamily="@font/roboto_medium"
                    android:textSize="12sp"
                    android:layout_marginTop="8dp"
                    android:text="Time sensitive exclusive deal expiring live within 24hrs or less"
                    />


            </LinearLayout>
            <RelativeLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="0.1"
                >
                <ImageView
                    android:layout_width="20dp"
                    android:layout_height="20dp"
                    android:layout_marginTop="20dp"
                    android:src="@drawable/arrow"
                    android:layout_centerHorizontal="true"

                    />

            </RelativeLayout>


        </LinearLayout>




    </android.support.v7.widget.CardView>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="OR"
        android:layout_below="@id/createSingleDealBut"
        android:layout_marginTop="30dp"
        android:layout_centerHorizontal="true"
        android:textColor="#000"
        android:textSize="20sp"
        android:fontFamily="@font/roboto_medium"
        android:id="@+id/or"
        />


    <android.support.v7.widget.CardView
        android:layout_width="match_parent"
        android:layout_height="130dp"
        android:layout_below="@id/or"
        android:layout_marginTop="20dp"
        android:layout_marginStart="30dp"
        android:layout_marginEnd="30dp"
        app:cardCornerRadius="15dp"
        app:cardElevation="5dp"
        android:id="@+id/createOngoingDealBut"


        >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="horizontal"
            android:layout_margin="5dp"
            android:weightSum="1"
            >

            <RelativeLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="0.3"
                >
                <ImageView
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_centerInParent="true"
                    android:src="@drawable/clock"
                    android:scaleType="centerInside"
                    android:layout_margin="15dp"
                    />

            </RelativeLayout>
            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="0.6"
                android:orientation="vertical">

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:fontFamily="@font/roboto_medium"
                    android:layout_marginTop="20dp"
                    android:text="Ongoing Deals List"
                    android:textColor="#000"
                    android:textSize="18sp"
                    />

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:fontFamily="@font/roboto_medium"
                    android:textSize="12sp"
                    android:layout_marginTop="8dp"
                    android:text="Ongoing daily/weekly time specific deal specials offered to all customers. Create a Happy Hour deals  menu"
                    />


            </LinearLayout>
            <RelativeLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="0.1"
                >
                <ImageView
                    android:layout_width="20dp"
                    android:layout_height="20dp"
                    android:layout_marginTop="20dp"
                    android:src="@drawable/arrow"
                    android:layout_centerHorizontal="true"

                    />

            </RelativeLayout>


        </LinearLayout>




    </android.support.v7.widget.CardView>

    <include layout="@layout/bottom_navigation" android:id="@+id/navigation" />


</RelativeLayout>

上述 XML 的预览是

design achieved so far

帮我在高程中添加绿色。任何帮助将不胜感激。 谢谢。

最佳答案

试试这个

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <RelativeLayout
        android:id="@+id/rel1"
        android:layout_width="match_parent"
        android:layout_height="60dp"
        android:background="@android:color/white"
        android:elevation="5dp">

        <ImageView
            android:id="@+id/backBut"
            android:layout_width="50dp"
            android:layout_height="40dp"
            android:layout_centerVertical="true"
            android:src="@drawable/ic_close" />

        <TextView
            android:id="@+id/textView4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:text="CREATE"
            android:textColor="#000"
            android:textSize="20sp" />

    </RelativeLayout>

    <android.support.v7.widget.CardView
        android:id="@+id/createSingleDealBut"
        android:layout_width="match_parent"
        android:layout_height="130dp"
        android:layout_below="@id/rel1"
        android:layout_marginStart="30dp"
        android:layout_marginTop="20dp"
        android:layout_marginEnd="30dp"
        app:cardCornerRadius="30dp"
        app:cardElevation="5dp">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@drawable/test"
            android:orientation="horizontal"
            android:weightSum="1">

            <RelativeLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="0.3">

                <ImageView
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_centerInParent="true"
                    android:layout_margin="20dp"
                    android:scaleType="centerInside"
                    android:src="@drawable/dishu" />

            </RelativeLayout>

            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="0.6"
                android:orientation="vertical">

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="20dp"
                    android:text="Single Deal"
                    android:textColor="#000"
                    android:textSize="18sp" />

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="8dp"
                    android:text="Time sensitive exclusive deal expiring live within 24hrs or less"
                    android:textSize="12sp" />


            </LinearLayout>

            <RelativeLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="0.1">

                <ImageView
                    android:layout_width="20dp"
                    android:layout_height="20dp"
                    android:layout_centerHorizontal="true"
                    android:layout_marginTop="20dp"

                    />

            </RelativeLayout>


        </LinearLayout>


    </android.support.v7.widget.CardView>

    <TextView
        android:id="@+id/or"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/createSingleDealBut"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="30dp"
        android:text="OR"
        android:textColor="#000"
        android:textSize="20sp" />


    <android.support.v7.widget.CardView
        android:id="@+id/createOngoingDealBut"
        android:layout_width="match_parent"
        android:layout_height="130dp"
        android:layout_below="@id/or"
        android:layout_marginStart="30dp"
        android:layout_marginTop="20dp"
        android:layout_marginEnd="30dp"
        app:cardCornerRadius="30dp"
        app:cardElevation="5dp">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@drawable/test"
            android:orientation="horizontal"
            android:weightSum="1">

            <RelativeLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="0.3">

                <ImageView
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_centerInParent="true"
                    android:layout_margin="15dp"
                    android:scaleType="centerInside" />

            </RelativeLayout>

            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="0.6"
                android:orientation="vertical">

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="20dp"
                    android:text="Ongoing Deals List"
                    android:textColor="#000"
                    android:textSize="18sp" />

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="8dp"
                    android:text="Ongoing daily/weekly time specific deal specials offered to all customers. Create a Happy Hour deals  menu"
                    android:textSize="12sp" />

            </LinearLayout>

            <RelativeLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="0.1">

                <ImageView
                    android:layout_width="20dp"
                    android:layout_height="20dp"
                    android:layout_centerHorizontal="true"
                    android:layout_marginTop="20dp"
                    android:src="@drawable/ic_apk_box" />

            </RelativeLayout>

        </LinearLayout>

    </android.support.v7.widget.CardView>

</RelativeLayout>

drawable/test

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item
        android:left="-8dp"
        android:right="-8dp"
        android:top="-8dp">
        <shape>
            <corners
                android:bottomLeftRadius="35dp"
                android:bottomRightRadius="35dp" />
            <stroke
                android:width="4dp"
                android:color="#17E208" />
        </shape>
    </item>
</layer-list>

输出

enter image description here

关于android - 如何在 Android View 下方设置高程颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54683807/

相关文章:

sql - 在 Sql Server 的 xml 中向第 n 个元素插入一个元素

java - 动态地将 JSON/XML 传递到 REST Web 服务

android - 使用消息和使用 Twitter Auth 在 Twitter 上发布图像的简单技术是什么?

java - 我如何遍历 android.graphics.Path 段?

java - JSON 解析为 Java - Android 应用程序

Android Studio 不执行 build.gradle

java - 从数据库获取日期并在 Java 中进行比较

java - 求助关于AndroidManifest.xml读取问题

android - 应用程序中的子菜单

android - 确定所呈现的软键盘的样式,平板电脑或手机样式