Search code examples
androidxmlandroid-relativelayoutgoogle-now

Designing similar Google Now card button - Need Feedback


I'm currently looking to implement the following "Google Now" type card. I have designed the following card below but are having troubles with extra space being created with my current layout arrangement. I just need a second opinion on how to maybe rewrite this XML in a more proper way.

Google Now - Card w/ Button design

Google Now - Card Example

Current Design

Current Designed - Google Now Card - Jaison B.

Im trying to get rid of this extra space in my current design.

XMl

  <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/main_background_grey"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >

<FrameLayout
    android:id="@+id/frameLayout1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:background="@drawable/card_background_full" >

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="16dp" >

        <TextView
            android:id="@+id/title_location"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:paddingBottom="4dp"
            android:text="Title"
            android:textAppearance="?android:attr/textAppearanceLarge" />

        <RelativeLayout
            android:id="@+id/relativeLayout1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentRight="true"
            android:layout_below="@+id/title_location"
            android:paddingBottom="2dp"
            android:paddingTop="2dp" >

            <TextView
                android:id="@+id/body_location_latlong_title"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="TEXT: "
                android:textAppearance="?android:attr/textAppearanceSmall"
                android:textStyle="bold" />

            <TextView
                android:id="@+id/body_location_latlong_result"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignBaseline="@+id/body_location_latlong_title"
                android:layout_alignBottom="@+id/body_location_latlong_title"
                android:layout_toRightOf="@+id/body_location_latlong_title"
                android:ellipsize="end"
                android:paddingLeft="4dp"
                android:singleLine="true"
                android:text="text, text, text..."
                android:textAppearance="?android:attr/textAppearanceSmall"
                android:textStyle="italic" />

        </RelativeLayout>

        <RelativeLayout
            android:id="@+id/RelativeLayout01"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentRight="true"
            android:layout_below="@+id/relativeLayout1"
            android:paddingBottom="2dp"
            android:paddingTop="2dp" >

            <TextView
                android:id="@+id/body_location_address_title"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="MORE TEXT: "
                android:textAppearance="?android:attr/textAppearanceSmall"
                android:textStyle="bold" />

            <TextView
                android:id="@+id/body_location_address_result"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignBaseline="@+id/body_location_address_title"
                android:layout_alignBottom="@+id/body_location_address_title"
                android:layout_toRightOf="@+id/body_location_address_title"
                android:ellipsize="end"
                android:paddingLeft="4dp"
                android:singleLine="true"
                android:text="text, text and more text..."
                android:textAppearance="?android:attr/textAppearanceSmall"
                android:textStyle="italic" />

        </RelativeLayout>

    </RelativeLayout>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="207dp"
        android:gravity="bottom" >

        <Button
            android:id="@+id/button1"
            style="@style/CardActionButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentRight="true"
            android:gravity="left|center_vertical|center_horizontal"
            android:text="Button" />

    </RelativeLayout>

</FrameLayout>

Styles

<style name="CardActionButton">
    <item name="android:textSize">16dp</item>
    <item name="android:textColor">@color/default_green</item>
    <item name="android:ellipsize">end</item>
    <item name="android:gravity">start|center</item>
    <item name="android:paddingLeft">16.0dip</item>
    <item name="android:paddingRight">4dp</item>
    <item name="android:maxLines">2</item>
    <item name="android:drawablePadding">4.0dip</item>
</style>

Drawable - Card Background - 144px/XXHDPI

144 - XXHDPI - Google Now - Card Background


Solution

  • You have too many nested layouts, try to have as few as possible nests. Here, I removed couple of them and the above mentioned empty space went away:

    layout xml:

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:background="@drawable/main_background"
        android:paddingBottom="@dimen/activity_vertical_margin"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin" >
    
        <RelativeLayout
            android:id="@+id/card_content"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:padding="16dp" >
    
            <TextView
                android:id="@+id/title_location"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:paddingBottom="4dp"
                android:text="@string/current_location"
                android:textAppearance="?android:attr/textAppearanceLarge" />
    
            <LinearLayout
                android:id="@+id/location"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:layout_alignParentRight="true"
                android:layout_below="@+id/title_location"
                android:orientation="horizontal"
                android:paddingBottom="2dp"
                android:paddingTop="2dp" >
    
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/lat_long"
                    android:textAppearance="?android:attr/textAppearanceSmall"
                    android:textStyle="bold" />
    
                <TextView
                    android:id="@+id/body_location_latlong_result"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:ellipsize="end"
                    android:paddingLeft="4dp"
                    android:singleLine="true"
                    android:text="@string/loading"
                    android:textAppearance="?android:attr/textAppearanceSmall"
                    android:textStyle="italic" />
            </LinearLayout>
    
            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:layout_alignParentRight="true"
                android:layout_below="@+id/location"
                android:orientation="horizontal"
                android:paddingBottom="2dp"
                android:paddingTop="2dp" >
    
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/address"
                    android:textAppearance="?android:attr/textAppearanceSmall"
                    android:textStyle="bold" />
    
                <TextView
                    android:id="@+id/body_location_address_result"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:ellipsize="end"
                    android:paddingLeft="4dp"
                    android:singleLine="true"
                    android:text="@string/loading"
                    android:textAppearance="?android:attr/textAppearanceSmall"
                    android:textStyle="italic" />
            </LinearLayout>
        </RelativeLayout>
    
        <Button
            android:id="@+id/button1"
            style="@style/CardActionButton"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentRight="true"
            android:layout_below="@id/card_content"
            android:gravity="left|center_vertical|center_horizontal"
            android:text="@string/button" />
    
    </RelativeLayout>
    

    Note that I have added a new drawable, main_background; that's to get rid of additional RelativeLayout/FrameLayout, and have both background image and color in one single drawable.

    main_background.xml:

    <?xml version="1.0" encoding="utf-8"?>
    <layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
    
        <item>
            <shape android:shape="rectangle" >
                <solid android:color="@color/main_background_grey" />
            </shape>
        </item>
        <item>
            <bitmap
                android:src="@drawable/card_background_full" />
        </item>
    
    </layer-list>
    

    Hope this helps.