Android Design - How to get this card view effect? - android

I am creating a weather app.
How do I get this card effect ? How do I get a textView in a card like that ?
This is my status:
Can someone show how to make this or something at least similar

frist of all below dependencies add in your build.gradle
compile 'com.android.support:cardview-v7:24.2.1'
and in xml you can write this code. its just sample design according to your need...
this will solve your question... How do I get this card effect ? How do I get a textView in a card like that ?
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView android:id="#+id/card1"
android:layout_width="match_parent"
android:layout_height="200dp"
app:cardElevation="5dp"
app:cardUseCompatPadding="true"
app:cardCornerRadius="5dp"
app:cardBackgroundColor="#android:color/white"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp">
<TextView
android:id="#+id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Detail"
android:textSize="20dp"
android:textColor="#color/colorPrimary"
android:layout_alignParentTop="true"
android:layout_marginRight="10dp"/>
<TextView
android:id="#+id/line"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#color/colorPrimary"
android:layout_below="#id/text1"/>
<TextView
android:id="#+id/text2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TUE"
android:textColor="#color/colorGrey"
android:layout_marginTop="10dp"
android:textSize="16dp"
android:layout_below="#+id/text1"/>
<TextView
android:id="#+id/text3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="NOON"
android:layout_marginTop="10dp"
android:textSize="16dp"
android:layout_toRightOf="#+id/text2"
android:layout_marginLeft="10dp"
android:layout_below="#+id/text1"
android:textColor="#color/colorTextBlackLight"/>
<TextView
android:id="#+id/text4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="EVE"
android:layout_marginTop="10dp"
android:textSize="16dp"
android:layout_toRightOf="#+id/text3"
android:layout_marginLeft="30dp"
android:layout_below="#+id/text1"
android:textColor="#color/colorTextBlackLight"/>
<TextView
android:id="#+id/text5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="NIGHT"
android:layout_marginTop="10dp"
android:textSize="16dp"
android:layout_toRightOf="#+id/text4"
android:layout_marginLeft="30dp"
android:layout_below="#+id/text1"
android:textColor="#color/colorTextBlackLight"/>
<TextView
android:id="#+id/text6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="WED"
android:layout_marginTop="10dp"
android:textSize="16dp"
android:layout_toRightOf="#+id/text5"
android:layout_marginLeft="30dp"
android:layout_below="#+id/text1"
android:textColor="#color/colorGrey"/>
<TextView
android:id="#+id/text7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="WED"
android:layout_marginTop="10dp"
android:textSize="16dp"
android:layout_toRightOf="#+id/text6"
android:layout_marginLeft="5dp"
android:layout_below="#+id/text1"
android:textColor="#color/colorTextBlackLight"/>
<TextView
android:id="#+id/text8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="21"
android:layout_marginTop="10dp"
android:textSize="16dp"
android:layout_marginLeft="5dp"
android:layout_below="#+id/text2"
android:textColor="#color/colorTextBlackLight"/>
<ImageView
android:id="#+id/img1"
android:layout_width="30dp"
android:layout_height="25dp"
android:src="#drawable/ic_like_icon"
android:scaleType="fitXY"
android:layout_marginTop="10dp"
android:layout_below="#+id/text3"
android:layout_toRightOf="#+id/text8"/>
<TextView
android:id="#+id/textmore"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="MORE"
android:textSize="18dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:textColor="#color/colorTextBlackLight"/>
</RelativeLayout>
</android.support.v7.widget.CardView>
you can use this xml in row.xml for using in recyclerview to create multiple use
for listing read tutorial:
http://www.androidhive.info/2016/05/android-working-with-card-view-and-recycler-view
hope it will helpfull for you. dont forgot to accept it if helpfull

Related

RelativeLayout breaks on pre-Marshmallow devices

I am facing a problem while populating a list view. Following is my layout for a list item.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:paddingLeft="10dp"
android:paddingRight="10dp">
<CheckBox
android:id="#+id/item_pay_periods_check_box"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_alignParentLeft="true"
android:button="#drawable/btn_check"
android:layout_below="#+id/item_pay_periods_date"
android:layout_marginTop="5dp"
android:layout_marginRight="5dp"
android:visibility="visible"/>
<TextView
android:id="#+id/item_pay_periods_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Mon Sep 12"
android:textSize="13sp"
android:layout_toRightOf="#+id/item_pay_periods_check_box"
android:layout_alignParentTop="true"/>
<TextView
android:id="#+id/item_pay_periods_time_in"
android:layout_width="70dp"
android:layout_height="wrap_content"
android:text="12:00 am"
android:layout_toRightOf="#+id/item_pay_periods_check_box"
android:layout_below="#+id/item_pay_periods_date"
android:layout_marginTop="5dp"
android:textSize="13sp"/>
<TextView
android:id="#+id/item_pay_periods_time_out"
android:layout_width="70dp"
android:layout_height="wrap_content"
android:textSize="13sp"
android:layout_below="#+id/item_pay_periods_time_in"
android:text="12:00 am"
android:layout_toRightOf="#+id/item_pay_periods_check_box"
android:layout_marginTop="5dp"/>
<TextView
android:id="#+id/item_pay_periods_service_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Attendant care service service service"
android:textSize="13sp"
android:textStyle="bold"
android:layout_alignBaseline="#+id/item_pay_periods_time_in"
android:layout_toRightOf="#+id/item_pay_periods_time_in"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:maxLines="1"
android:ellipsize="end"
android:layout_toLeftOf="#+id/item_pay_periods_duration"
android:layout_toStartOf="#+id/item_pay_periods_duration" />
<TextView
android:id="#+id/item_pay_periods_activities"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLines="1"
android:ellipsize="end"
android:text="Housework, shopping, shopping, shopping"
android:layout_below="#+id/item_pay_periods_service_name"
android:layout_toRightOf="#+id/item_pay_periods_time_out"
android:layout_marginLeft="5dp"
android:layout_alignBaseline="#+id/item_pay_periods_time_out"
android:layout_marginRight="5dp"
android:layout_toLeftOf="#+id/item_pay_periods_duration"
android:layout_toStartOf="#+id/item_pay_periods_duration"
android:visibility="visible"/>
<LinearLayout
android:id="#+id/itemPayPeriodsNotesLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_below="#+id/item_pay_periods_activities"
android:layout_toRightOf="#+id/item_pay_periods_time_out"
android:layout_marginLeft="5dp"
android:layout_toLeftOf="#+id/item_pay_periods_duration"
android:layout_toStartOf="#+id/item_pay_periods_duration"
android:layout_marginTop="5dp">
<ImageView
android:id="#+id/item_pay_periods_img_tag"
android:layout_width="15dp"
android:layout_height="15dp"
android:src="#drawable/ic_tag"
android:layout_gravity="center_vertical"/>
<TextView
android:id="#+id/item_pay_periods_notes"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLines="1"
android:ellipsize="end"
android:text="made trip to CVC"
android:textSize="13sp"
android:layout_marginLeft="5dp"
android:layout_gravity="center_vertical"/>
</LinearLayout>
<TextView
android:id="#+id/item_pay_periods_duration"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="5h 00m"
android:textSize="13sp"
android:layout_alignBaseline="#+id/item_pay_periods_time_in"
android:layout_alignBottom="#+id/item_pay_periods_time_in"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:visibility="visible"/>
<ImageView
android:id="#+id/item_pay_periods_img_submit_check_icon"
android:layout_width="15dp"
android:layout_height="15dp"
android:src="#drawable/ic_check"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:tint="#color/blue"
android:visibility="visible"/>
<TextView
android:id="#+id/item_pay_periods_entry_status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="#+id/item_pay_periods_img_submit_check_icon"
android:text="Rejected"
android:textSize="12sp"
android:textColor="#color/red"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true" />
</RelativeLayout>
This is how it looks on Marshmallow and Nougat devices
Not overlapping views
And this is how it looks on Lollipop and pre lollipop devices
Overlapping views
Can anyone tell me why this is happening? Or anybody have faced such issue? Thanks in advance.

Make textview expand in recyclerView

I have an item of RecyclerView that looks :
If user click on the help icon, I want to show a description of the item in the middle expanding the height of the item like this:
I tryed differents ways but I cant make it work, I tryed to set the height of the parent ( but I dont think this is a good approach, since it should get the size automattically in fuction of how many text have the description) but it doesnt work, make layout wrap content doesnt work either since it is a RelativeLayout with alignparent bottom, any help will be great
Layout
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/ll"
android:layout_width="wrap_content"
android:layout_height="80dp"
android:layout_centerHorizontal="true"
android:layout_margin="10dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:animateLayoutChanges="true"
android:background="#drawable/stroke_shop_adapter"
android:orientation="vertical">
<TextView
android:id="#+id/nombre"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_gravity="center"
android:layout_margin="5dp"
android:layout_marginTop="10dp"
android:layout_toRightOf="#+id/img"
android:layout_toLeftOf="#+id/ayuda"
android:gravity="center|top"
android:text="#string/level"
android:textColor="#fff"
android:textSize="15sp" />
<ImageView
android:id="#+id/img"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_gravity="center"
android:src="#drawable/cubo" />
<TextView
android:id="#+id/descripcion"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/img"
android:layout_toLeftOf="#+id/ayuda"
android:layout_below="#+id/separador1"
android:layout_above="#+id/coste"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:gravity="center"
android:text=""
android:textColor="#fff"
android:textSize="14sp" />
<ImageView
android:id="#+id/ayuda"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="10dp"
android:src="#drawable/ayuda_icon"/>
<TextView
android:id="#+id/coste"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_toLeftOf="#+id/ayuda"
android:gravity="center"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="10dp"
android:text="100$"
android:textColor="#fff"
android:textSize="13sp" />
<View
android:id="#+id/separador1"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_below="#id/nombre"
android:layout_toRightOf="#+id/img"
android:layout_toLeftOf="#+id/ayuda"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="2dp"
android:background="#00c6ff"/>
<TextView
android:id="#+id/nivel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:layout_toRightOf="#+id/img"
android:layout_alignParentBottom="true"
android:text="Level: 5/7"
android:textColor="#fff"
android:textSize="13sp" />
<TextView
android:id="#+id/maxNivel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#id/separador1"
android:layout_marginBottom="5dp"
android:layout_marginRight="20dp"
android:layout_marginTop="5dp"
android:text=""
android:textColor="#fff"
android:textSize="17sp" />
Try layout as:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/colorBlack"
android:orientation="vertical">
<ImageView
android:id="#+id/img"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:src="#mipmap/ic_launcher"/>
<ImageView
android:id="#+id/ayuda"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginBottom="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:src="#mipmap/ic_launcher"/>
<TextView
android:id="#+id/nombre"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_gravity="center"
android:layout_margin="5dp"
android:layout_marginTop="10dp"
android:layout_toLeftOf="#+id/ayuda"
android:layout_toRightOf="#+id/img"
android:gravity="center|top"
android:text="Level"
android:textColor="#fff"
android:textSize="15sp"/>
<View
android:id="#+id/separador1"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_below="#id/nombre"
android:layout_marginBottom="2dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_toLeftOf="#+id/ayuda"
android:layout_toRightOf="#+id/img"
android:background="#00c6ff"/>
<TextView
android:id="#+id/descripcion"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/separador1"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_toLeftOf="#+id/ayuda"
android:layout_toRightOf="#+id/img"
android:text="content desc content desc content desc content desc content desc content desc content desc "
android:textColor="#fff"
android:gravity="center_horizontal"
android:textSize="14sp"/>
<TextView
android:id="#+id/nivel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/descripcion"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:layout_toRightOf="#+id/img"
android:text="Level: 5/7"
android:textColor="#fff"
android:textSize="13sp"/>
<TextView
android:id="#+id/coste"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/descripcion"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_toLeftOf="#+id/ayuda"
android:gravity="center"
android:text="100$"
android:textColor="#fff"
android:textSize="13sp"/>
</RelativeLayout>
In that case you can use Expandable-RecyclerView
Download the latest AAR via Maven:
<dependency>
<groupId>com.levelupstudio</groupId>
<artifactId>expandable-recyclerview</artifactId>
<version>1.0.1</version>
</dependency>
or Gradle:
compile 'com.levelupstudio:expandable-recyclerview:1.0.1'
Other option is to use
You can try with ExpandableHeightListView
Add ExpandableHeightListView instead of ListView in your xml files:
<ScrollView 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">
<com.github.paolorotolo.expandableheightlistview.ExpandableHeightListView
android:id="#+id/expandable_listview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="8dp">
</com.github.paolorotolo.expandableheightlistview.ExpandableHeightListView>
</ScrollView>
Add this to your build.gradle:
repositories {
mavenCentral()
}
dependencies {
compile 'com.github.paolorotolo:expandableheightlistview:1.0.0'
}

TextView above and exactly centered of the image view works perfectly but in the case high end device the TextView is slightly up. Why?

I make the single_row.xml for the custom adapter which works perfectly on several devices but in the case of HighEnd device , the TextVIew is slightly up from the center. Why ??Please Help..
Image Link to understand the question Clearly
single_row.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageViewSingleRow"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:src="#drawable/one"
android:paddingTop="12dp"
android:paddingBottom="12dp"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:adjustViewBounds="true"
/>
<TextView
android:paddingTop="10dp"
android:paddingBottom="6dp"
android:paddingLeft="5dp"
android:paddingRight="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Title text here"
android:id="#+id/textViewTitle"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignBottom="#+id/imageViewSingleRow"
android:layout_toRightOf="#+id/imageViewSingleRow"
android:layout_toEndOf="#+id/imageViewSingleRow"
android:textSize="18dp"
android:gravity="center_vertical"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:textSize="20sp"
android:textStyle="normal"
android:id="#+id/textViewNumbering"
android:layout_alignLeft="#+id/imageViewSingleRow"
android:layout_alignTop="#+id/imageViewSingleRow"
android:layout_alignRight="#+id/imageViewSingleRow"
android:layout_alignBottom="#+id/imageViewSingleRow"
android:gravity="center"
/>
<TextView
android:visibility="gone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="description"
android:id="#+id/textViewDescription"
android:layout_below="#+id/textViewTitle"
android:layout_centerHorizontal="true" />
<TextView
android:visibility="gone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="imageLink"
android:id="#+id/textViewImageLink"
android:layout_below="#+id/textViewDescription"
android:layout_alignRight="#+id/textViewDescription"
android:layout_alignEnd="#+id/textViewDescription"
/>
</RelativeLayout>
Finally done for the high end devices too..
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:text="1"
android:padding="26dp"
android:textStyle="bold"
android:id="#+id/textViewNumbering"
android:layout_alignTop="#+id/imageViewSingleRow"
android:layout_alignBottom="#+id/imageViewSingleRow"
android:gravity="center"
/>

Android Textview not showing multiple lines within a list

May be this is a duplicate question,but I am asking it again because the solutions here is not working for me.I have a listview and within the list view I have 2 imageviews and a textview.Refer to the image below:
As you can see I cannot split the textviews into 2 lines and as a result my textview is overlapping with that of the imageview.Here is my code:
uplodefilelist.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/rl_filelist"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:paddingBottom="20dp"
android:paddingTop="20dp" >
<ImageView
android:id="#+id/fileimage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginLeft="10dp"
android:src="#drawable/default_avatar" />
<RelativeLayout
android:id="#+id/ll_cntactcont"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="5dp"
android:layout_marginTop="10dp"
android:layout_toRightOf="#+id/fileimage" >
<TextView
android:id="#+id/tvfilename"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:text="Srina Banerjee"
android:textColor="#000000"
android:textStyle="bold"
android:ellipsize="end"
android:maxLines="2"
android:singleLine="false"
/>
<ImageView
android:id="#+id/btnSettings"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:src="#drawable/settings"
android:textColor="#000000"
android:focusable="false"
android:focusableInTouchMode="false" />
</RelativeLayout>
</RelativeLayout>
I cannot use any html format within the setText() method or I cannot do anything from java file.I have to do it from within the xml file only.I consulted our very own stack overflow and added this lines in my textview.
android:ellipsize="end"
android:maxLines="2"
android:singleLine="false"
But as you can see the image none of them are working.Help.
just add 1 tag in to Textview That
android:layout_toLeftOf="#+id/btnSettings"
So this old one is
<TextView
android:id="#+id/tvfilename"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:text="Srina Banerjee"
android:textColor="#000000"
android:textStyle="bold"
android:ellipsize="end"
android:maxLines="2"
android:singleLine="false"/>
Change to :
<TextView
android:id="#+id/tvfilename"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:text="Srina Banerjee"
android:textColor="#000000"
android:layout_toLeftOf="#+id/btnSettings"
android:textStyle="bold"
android:ellipsize="end"
android:maxLines="2"
android:singleLine="false"/>
Try this way,hope this will help you to solve your problem.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:gravity="center">
<ImageView
android:id="#+id/fileimage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher"
android:adjustViewBounds="true"/>
<LinearLayout
android:id="#+id/ll_cntactcont"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp">
<TextView
android:id="#+id/tvfilename"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Srina Banerjee"
android:textColor="#000000"
android:textStyle="bold"
android:ellipsize="end"
android:maxLines="2"/>
</LinearLayout>
<ImageView
android:id="#+id/btnSettings"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher"
android:textColor="#000000"
android:focusable="false"
android:focusableInTouchMode="false"
android:layout_marginLeft="5dp"/>
</LinearLayout>
add android:layout_toLeftOf="#+id/btnSettings" in your textview as
<TextView
android:id="#+id/tvfilename"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:text="Srina Banerjee"
android:textColor="#000000"
android:textStyle="bold"
android:ellipsize="end"
android:maxLines="2"
android:singleLine="false"
android:layout_toLeftOf="#+id/btnSettings"
/>
And don't forget to clear the project.
Add android:layout_toLeftOf="#+id/btnSettings" in textview and remove its parent relative layout
try this layout
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/rl_filelist"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:paddingBottom="20dp"
android:paddingTop="20dp" >
<ImageView
android:id="#+id/fileimage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginLeft="10dp"
android:src="#drawable/default_avatar" />
<TextView
android:id="#+id/tvfilename"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_toLeftOf="#+id/btnSettings"
android:layout_toRightOf="#+id/fileimage"
android:ellipsize="end"
android:maxLines="2"
android:singleLine="false"
android:text="Srina Banerjee"
android:textColor="#000000"
android:textStyle="bold" />
<ImageView
android:id="#+id/btnSettings"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:focusable="false"
android:focusableInTouchMode="false"
android:src="#drawable/settings"
android:textColor="#000000" />
</RelativeLayout>
you just have to add one line to your TextView
android:layout_toLeftOf="#+id/btnSettings"
Try this Code...
<ImageView
android:id="#+id/fileimage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginLeft="10dp"
android:src="#drawable/default_avatar" />
<RelativeLayout
android:id="#+id/ll_cntactcont"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="5dp"
android:layout_marginTop="10dp"
android:layout_toRightOf="#+id/fileimage" >
<TextView
android:id="#+id/tvfilename"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:text="Srina Banerjee "
android:layout_toLeftOf="#+id/btnSettings" <!-- use this for setting textview properly -->
android:textColor="#000000"
android:lines="2" <!-- put this line if you always want to show 2 lines -->
android:textStyle="bold"
android:maxLines="2" <!-- max number of size... used when text is long -->
/>
<ImageView
android:id="#+id/btnSettings"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:src="#drawable/settings"
android:textColor="#000000"
android:focusable="false"
android:focusableInTouchMode="false" />
</RelativeLayout>
Your textview needs to be a specific width for it to wrap not wrap content. You probably want to do a LinearLayout and not Relative for those 3 views.

Create a listview with sides like older email android app

I want to create a listview like older gmail app. See the screenshot:
I tried putting an empty view like this:
<TextView
android:id="#+id/color_highlight"
android:layout_width="5dp"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:background="#ff0000"
android:minHeight="48dp" />
<TextView
android:id="#+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginRight="20dp"
android:layout_marginTop="10dp"
android:layout_toLeftOf="#id/color_highlight"
android:text="Mudit Agarwal"
android:textStyle="bold"
android:textColor="#242424"
android:textIsSelectable="false"
android:textSize="22sp" />
<TextView
android:id="#+id/number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="#id/name"
android:layout_below="#id/name"
android:text="9933445566"
android:textColor="#777777"
android:textIsSelectable="false"
android:layout_marginBottom="10dp"
android:textSize="15sp" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:padding="3dp"
android:src="#drawable/contact" />
but this is not taking full height of the view. Please suggest.
What I changed is
android:layout_alignBottom="#+id/number"
to your color_highlight TextView. and instead of margin, I put padding like below in number TextView.
android:paddingBottom="20dp"
just put following layout code.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/color_highlight"
android:layout_width="5dp"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_alignBottom="#+id/number"
android:background="#ff0000"
android:minHeight="48dp" />
<TextView
android:id="#+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginRight="20dp"
android:layout_marginTop="10dp"
android:layout_toLeftOf="#id/color_highlight"
android:text="Mudit Agarwal"
android:textColor="#242424"
android:textIsSelectable="false"
android:textSize="22sp"
android:textStyle="bold" />
<TextView
android:id="#+id/number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="#id/name"
android:layout_below="#id/name"
android:paddingBottom="20dp"
android:text="9933445566"
android:textColor="#777777"
android:textIsSelectable="false"
android:textSize="15sp" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:padding="3dp"
android:src="#drawable/contact" />
</RelativeLayout>
I'm not sure but you can try putting android:layout_height="0dip" instead of android:layout_height="match_parent".

Categories

Resources