lundi 4 mai 2015

Fragments, Cards, ListViews and Images

It has been a long time since I did some Android and now I want to get back to it. I still try to grasp the concept of using Fragments properly and what would be the proper way to do what I need to.

To the point. I need to have a Main view that (for now) contains one card. This card will contain a TextView and a ListView with custom items(one image and two rows of text). How would I implement this?

Do I need to do a different fragment for the listView and another for the card? I know I need a custom Adapter for the list view but how do I go on putting everything together?

Any advice is welcomed, even in the most basic diagram form.

fragment_main.xml

<LinearLayout  xmlns:android="http://ift.tt/nIICcg"
    xmlns:tools="http://ift.tt/LrGmb4" android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/white"
    tools:context=".MainActivity$PlaceholderFragment"
    android:paddingLeft="5dp"
    android:paddingTop="10dp"
    android:paddingRight="5dp"
    android:paddingBottom="10dp">


    <android.support.v7.widget.CardView
        android:id="@+id/accounts_card"
        xmlns:card_view="http://ift.tt/GEGVYd"
        android:layout_gravity="top"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:minHeight="150dp"
        android:layout_marginLeft="5dp"
        card_view:cardCornerRadius="0dp"
        card_view:cardBackgroundColor="@color/white"
        card_view:cardElevation="3dp"
        android:layout_marginRight="5dp"
        android:layout_marginTop="10dp"
        android:layout_marginBottom="5dp">

        <RelativeLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content">
            <TextView
                android:id="@+id/accounts_title"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                style="@style/Base.TextAppearance.AppCompat.Caption"
                android:elevation="1dp"
                android:text="My Accounts"
                android:gravity="top|center"
                android:textStyle="bold"
                android:textSize="20dp"
                android:paddingTop="15dp"
                android:paddingBottom="15dp" />

            <ListView
                android:id="@+id/accounts_list"
                android:layout_below="@id/accounts_title"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1" />

        </RelativeLayout>

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

</LinearLayout>

my_listitem.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://ift.tt/nIICcg"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/account_item">

    <ImageButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/b_logo"
        android:elevation="1dp"/>

    <LinearLayout
        android:layout_alignEnd="@id/b_logo"
        android:paddingLeft="2dp"
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="right">
        <TextView
            android:id="@+id/account_number"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="9959593922923"/>
        <TextView
            android:id="@+id/account_code"
            android:layout_below="@id/account_number"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceSmall"
            android:text="30-15-55"/>
    </LinearLayout>

</RelativeLayout>

Aucun commentaire:

Enregistrer un commentaire