I am making an application to display movies sorted by Popularity and date.
When I click on a movie, it takes me to the description of the movie. I am using RelativeLayout for the description UI. But the movie name is truncated if its too large.
I have tried few solutions from stackoverflow for the textView like
android:scrollHorizontally="true"
android:ellipsize="end"
android:lines="1"
I know there's one solution of using LinearLayout. But I wanted to know if there's a solution using RelativeLayout only.
Please Find the screenshot by clicking on this link. The text gets truncated and its replaced by three dots
Here's the full code :
<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"
android:fillViewport="true">
<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="?android:attr/listPreferredItemHeight"
android:paddingStart="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin_less"
android:paddingTop="#dimen/activity_vertical_margin_less"
android:paddingBottom="#dimen/activity_vertical_margin_less"
tools:context="com.example.puneet.movieout.MovieInfoDisplay"
>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Movie Title"
android:id="#+id/textView"
android:textStyle="bold"
android:layout_below="#+id/imageView"
android:layout_alignParentStart="true"
android:layout_marginTop="20dp"
android:textColor="#color/black"
android:textSize="20sp" />
<TextView
android:scrollHorizontally="true"
android:ellipsize="end"
android:lines="1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="Movie name is Long. Movie name is Long"
android:layout_marginTop="20dp"
android:id="#+id/textView2"
android:layout_above="#+id/textView4"
android:layout_toRightOf="#id/textView"
android:layout_alignStart="#+id/textView6"
android:layout_below="#+id/imageView"
android:textSize="20sp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="User Rating"
android:id="#+id/textView3"
android:textStyle="bold"
android:layout_below="#+id/textView2"
android:layout_alignParentStart="true"
android:textColor="#color/black"
android:textSize="20sp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="User Rating"
android:layout_toRightOf="#id/textView3"
android:id="#+id/textView4"
android:layout_below="#+id/textView"
android:layout_alignStart="#+id/textView6"
android:textSize="20sp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Release Date"
android:id="#+id/textView5"
android:textStyle="bold"
android:layout_below="#+id/textView3"
android:layout_alignParentStart="true"
android:textColor="#color/black"
android:layout_marginRight="10dp"
android:textSize="20sp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Text"
android:id="#+id/textView6"
android:layout_toRightOf="#id/textView5"
android:layout_below="#+id/textView4"
android:textSize="20sp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Overview"
android:id="#+id/textView7"
android:textStyle="bold"
android:layout_below="#+id/textView5"
android:layout_alignParentStart="true"
android:textColor="#color/black"
android:textSize="20sp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Text"
android:id="#+id/textView8"
android:layout_toRightOf="#id/textView7"
android:layout_below="#+id/textView6"
android:layout_alignStart="#+id/textView6"
android:textSize="20sp"/>
</RelativeLayout>
</ScrollView>
If you don't want to get the text truncated , you have to remove the ellipsize attribute and add your TextView inside HorizontalScrollView.
Your view should be like :
<HorizontalScrollView
android:id="#+id/txt_scrollview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_above="#+id/textView4"
android:layout_toRightOf="#id/textView"
android:layout_alignStart="#+id/textView6"
android:layout_below="#+id/imageView"
android:scrollbars="none"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="Movie name is Long. Movie name is Long"
android:id="#+id/textView2"
android:textSize="20sp"/>
</HorizontalScrollView>
This way you can embed your text inside the scroll without the text being truncated.
Related
I have implemented code for navigation header where I am using one NetworkImageView and image is shown with padding 10dp on left side my issue is I used android:layout_centerVertical="true" but it's not working on lollipop, marshmallow version. I run my app on kitkat version then the image has left padding with center vertical. Please tell me where I am wrong?
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:paddingBottom="20dp"
android:background="#e6e3e3"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.android.volley.toolbox.NetworkImageView
android:layout_marginLeft="10dp"
android:layout_marginTop="30dp"
android:layout_width="50dp"
android:layout_height="80dp"
android:scaleType="fitXY"
android:id="#+id/imageView1"/>
<TextView
android:id="#+id/tv_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="12dp"
android:singleLine="true"
android:textStyle="bold"
android:layout_marginLeft="5dp"
android:layout_marginTop="30dp"
android:layout_toRightOf="#+id/imageView1"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="10dp"
android:id="#+id/tv_email"
android:textStyle="bold"
android:singleLine="true"
android:layout_marginLeft="5dp"
android:layout_marginTop="2dp"
android:layout_toRightOf="#+id/imageView1"
android:layout_below="#+id/tv_name"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Reg Date : "
android:textSize="10dp"
android:textStyle="bold"
android:id="#+id/reg_date"
android:singleLine="true"
android:layout_marginLeft="5dp"
android:layout_marginTop="2dp"
android:layout_toRightOf="#+id/imageView1"
android:layout_below="#+id/tv_email"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="10dp"
android:id="#+id/tv_reg_date"
android:singleLine="true"
android:layout_marginLeft="1dp"
android:layout_marginTop="2dp"
android:layout_toRightOf="#+id/reg_date"
android:layout_below="#+id/tv_email"/>
<TextView
android:id="#+id/lastlogin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/reg_date"
android:layout_marginLeft="5dp"
android:layout_marginTop="2dp"
android:layout_toRightOf="#+id/imageView1"
android:singleLine="true"
android:text="Last Login : "
android:textSize="10dp"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="10dp"
android:id="#+id/last_login"
android:singleLine="true"
android:layout_marginLeft="1dp"
android:layout_marginTop="2dp"
android:layout_toRightOf="#+id/lastlogin"
android:layout_below="#+id/tv_reg_date"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Membership : "
android:textStyle="bold"
android:textSize="10dp"
android:id="#+id/membershipStatus"
android:singleLine="true"
android:layout_marginLeft="5dp"
android:layout_marginTop="2dp"
android:layout_toRightOf="#+id/imageView1"
android:layout_below="#+id/lastlogin"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="10dp"
android:id="#+id/tv_status"
android:singleLine="true"
android:layout_marginLeft="1dp"
android:layout_marginTop="2dp"
android:layout_toRightOf="#+id/membershipStatus"
android:layout_below="#+id/last_login"/>
</RelativeLayout>
Please check your layout file. Its not version issue.
I would like to have a two textView on the same line. Below you can see what is the interaction when my String object is long and when is short.
I'm trying to do this in android xml view.
(Second text have to stay on the right of the first one when the first one is short)
Here is my code:
<LinearLayout
android:layout_width="0dp"
android:layout_height="35dp"
android:layout_weight="1"
android:gravity="start|center_vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="1"
android:paddingRight="40dp"
android:scrollHorizontally="true"
android:text="TextView long"
android:textColor="#android:color/white"
android:textSize="15sp" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:maxLines="1"
android:text="Text"
android:textColor="#android:color/white"
android:textSize="15sp" />
</RelativeLayout>
</RelativeLayout>
</LinearLayout>
My problem here is that my second text "Text" stay on the right parent each time...
Use tablelayout and put both textbox in table row have a try.Check this code.
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:stretchColumns="1"
android:layout_margin="10dp"
android:background="#android:color/white"
android:shrinkColumns="0"
>
<TableRow>
<TextView android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView toooooooooooooooooooooooooooooooooooo long"
android:layout_marginLeft="10dp"
android:ellipsize="end"
android:singleLine="true"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Textview"
android:gravity="start"
android:textColor="#android:color/black"
android:layout_marginLeft="5dp"
android:layout_marginRight="10dp"
android:ellipsize="none"
android:singleLine="true"
/>
</TableRow>
</TableLayout>
You can use weight in first TextView. Check this code.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="5dp"
android:gravity="start|center_vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="1"
android:paddingRight="40dp"
android:scrollHorizontally="true"
android:text="TextView toooooooooooooooooooooooooooooooooooo long"
android:textSize="15sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:maxLines="1"
android:text="Simple Text"
android:textSize="15sp" />
</LinearLayout>
I have a textView in a list item with another text view below it.
I am facing one problem again and again that when text increases . text view above overrides my text view below or text view below comes on top of text view above.
My XML in RelativeLayout is :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/tp_activity_wise_badge_fragment_each_item"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/tp_White"
android:minHeight="60dp">
<TextView
android:id="#+id/textview1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:layout_marginLeft="23dp"
android:layout_marginStart="23dp"
android:text="Loading Title..."
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#737574"
android:textSize="15dp"
android:textStyle="bold" />
<TextView
android:id="#+id/textview3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/textview1"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/textview1"
android:layout_centerVertical="true"
android:layout_marginEnd="23dp"
android:layout_marginRight="23dp"
android:background="#color/tp_White"
android:gravity="center_vertical|center_horizontal"
android:maxLines="2"
android:text="Loading..."
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#737574"
android:textSize="15dp" />
<TextView
android:id="#+id/textview2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Loading Subtitle..."
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#color/tp_inactive_channel_text_color"
android:textSize="11dp"
android:layout_below="#+id/textview1"
android:layout_alignLeft="#+id/textview1"
android:layout_alignStart="#+id/textview1" />
i know this is very basic problem but this is very undefined for me and i am not able to position this views such that they dont cut each other.
Any help will be appreciated.
You need to use layout_alignParentRight in your code.
its not proper way you set margin to set view
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/tp_activity_wise_badge_fragment_each_item"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/tp_White"
android:minHeight="60dp">
<TextView
android:id="#+id/textview1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Loading Title..."
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#737574"
android:textSize="15dp"
android:textStyle="bold" />
<TextView
android:id="#+id/textview3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/textView1"
android:layout_alignParentRight="true"
android:gravity="right"
android:background="#color/tp_White"
android:maxLines="2"
android:text="Loading..."
android:textColor="#737574"
android:textSize="15dp" />
<TextView
android:id="#+id/textview2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Loading Subtitle..."
android:textSize="11dp"
android:layout_below="#id/textview1"
/>
What are you trying to achieve by writing android:layout_alignTop="#+id/textview1" and at same time android:layout_alignBottom="#+id/textview1".
Instead you can try android:layout_below="#+id/textview1" this will align your textview vertically.
You should use LinearLayout (just copy and paste it)
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/tp_activity_wise_badge_fragment_each_item"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_margin="25dp"
>
<LinearLayout
android:layout_width="match_parent"
android:orientation="horizontal"
android:layout_marginBottom="10dp"
android:layout_height="wrap_content">
<TextView
android:id="#+id/textview1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Loading Title..."
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#737574"
android:textSize="15dp"
android:textStyle="bold" />
<TextView
android:id="#+id/textview3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="right"
android:text="Loading..."
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#737574"
android:textSize="15dp" />
</LinearLayout>
<TextView
android:id="#+id/textview2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Loading Subtitle..."
android:textAppearance="?android:attr/textAppearanceSmall"
android:textSize="11dp"
/>
</LinearLayout>
I developed an android application in which the scroll-view is not scrolling.. I am posting the code here pls check and if found any error pls help.. Here I used Linear Layout as root and then Scroll-view and Relative Layout inside the scroll-view and ... text-views inside relative layout... but this is not scrolling up..
XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#color/orange"
android:orientation="vertical" >
<RelativeLayout
android:id="#+id/header901"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/green"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="5dp"
android:gravity="center">
<TextView
android:id="#+id/headertext901"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_margin="5dp"
android:gravity="center"
android:textColor="#ffffff"
android:textSize="20sp"
android:text="Result"
android:textStyle="bold"
/>
</RelativeLayout>
<ScrollView
android:id="#+id/scrollView901"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scrollbars="vertical"
android:fillViewport="true">
<RelativeLayout
android:id="#+id/lLayout901"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="16dp"
android:layout_marginTop="22dp"
android:text="Your Destiny number is :" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/textView1"
android:layout_alignBottom="#+id/textView1"
android:layout_alignParentRight="true"
android:layout_marginRight="44dp"
android:text="TextView" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView1"
android:layout_below="#+id/textView1"
android:layout_marginTop="18dp"
android:text="Your result is loading......" />
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView3"
android:layout_below="#+id/textView3"
android:layout_marginTop="16dp"
android:text="Your Talent Number is :" />
<TextView
android:id="#+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/textView4"
android:layout_alignBottom="#+id/textView4"
android:layout_alignLeft="#+id/textView2"
android:text="TextView" />
<TextView
android:id="#+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView4"
android:layout_below="#+id/textView4"
android:layout_marginTop="20dp"
android:text="Your result is loading......." />
<TextView
android:id="#+id/textView7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView6"
android:layout_below="#+id/textView6"
android:layout_marginTop="16dp"
android:text="Your Heart Number is :" />
<TextView
android:id="#+id/textView8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/textView7"
android:layout_alignBottom="#+id/textView7"
android:layout_alignLeft="#+id/textView5"
android:text="TextView" />
<TextView
android:id="#+id/textView9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView7"
android:layout_centerVertical="true"
android:text="Your result is loading...." />
<TextView
android:id="#+id/textView10"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView9"
android:layout_below="#+id/textView9"
android:layout_marginTop="20dp"
android:text="Your Personality number is :" />
<TextView
android:id="#+id/textView11"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/textView10"
android:layout_alignLeft="#+id/textView8"
android:text="TextView" />
<TextView
android:id="#+id/textView12"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView10"
android:layout_below="#+id/textView10"
android:layout_marginTop="18dp"
android:text="Your result is loading...." />
<TextView
android:id="#+id/textView13"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView12"
android:layout_below="#+id/textView12"
android:layout_marginTop="18dp"
android:text="Your Minor expression no:" />
<TextView
android:id="#+id/textView14"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/textView13"
android:layout_alignLeft="#+id/textView11"
android:text="TextView" />
<TextView
android:id="#+id/textView15"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView13"
android:layout_below="#+id/textView13"
android:layout_marginTop="18dp"
android:text="Your result is loading....." />
<TextView
android:id="#+id/textView16"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView15"
android:layout_below="#+id/textView15"
android:layout_marginTop="18dp"
android:text="Your Minor Heart Desire no:" />
<TextView
android:id="#+id/textView17"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/textView16"
android:layout_alignLeft="#+id/textView14"
android:text="TextView" />
<TextView
android:id="#+id/textView18"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView16"
android:layout_below="#+id/textView16"
android:layout_marginTop="18dp"
android:text="Your result is loading....." />
<TextView
android:id="#+id/textView19"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView18"
android:layout_below="#+id/textView18"
android:layout_marginTop="18dp"
android:text="Your Minor Personality no:" />
<TextView
android:id="#+id/textView20"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/textView19"
android:layout_alignLeft="#+id/textView17"
android:text="TextView" />
<TextView
android:id="#+id/textView21"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView19"
android:layout_below="#+id/textView19"
android:layout_marginTop="18dp"
android:text="Your result is loading....." />
</RelativeLayout>
</ScrollView>
</LinearLayout>
You have used fill parent for your Scrollview height layout
Use android:layout_height="wrap_content" for scrollview
And i am sugesting to use LinearLayout with vertical orientation layout for this kind of use
Remove RelativeLayout with id "header901", it is useless, you can just leave headertext901 withe the main LinearLayout as parent ...
Then remove the following tags from SCrollView :
android:scrollbars="vertical"
android:fillViewport="true"
I would also advise to replace your RelativeLayout with id "lLayout901" by a LinearLayout, and follow #Martin Marconcini's advice to replace fill_parent with match_parent.
I am having an issue with getting my date TextView to be below my unit TextView when the activity name is too long in the rows for my ListView.
Here is my row layout code for my listview:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Name"
android:id="#+id/activityName"
android:textSize="25dp"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="#+id/pound"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="unit"
android:id="#+id/unit"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:layout_marginRight="5dp"
android:textSize="20dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="/"
android:id="#+id/slash"
android:layout_toLeftOf="#+id/unit"
android:layout_centerVertical="true"
android:layout_marginRight="2dp"
android:textSize="20dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Number"
android:id="#+id/number"
android:layout_centerVertical="true"
android:layout_toLeftOf="#+id/slash"
android:layout_marginRight="5dp"
android:textSize="20dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#"
android:id="#id/pound"
android:layout_centerVertical="true"
android:layout_toLeftOf="#+id/number"
android:layout_marginRight="2dp"
android:textSize="20dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Date"
android:id="#+id/date"
android:layout_below="#+id/unit"
android:layout_alignRight="#+id/unit"
android:textSize="10sp" />
</RelativeLayout>
My ListView rows look like this:
Question:
How do I get my date TextView to always be below my unit TextView? Also for the pound, number, slash, and unit TextViews to be all on the same line and all above the date Textview. As well as the activityName TextView to be the left of the pound TextView so it does not overlap with the pound, number, slash, and unit TextViews. Like what the walk and exercise rows look like.
Take a LinearLayout for right sided items(unit,date,slash etc.)
put it in relative layout and set as align_parentright = "true"
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="10dip"
android:paddingRight="10dip" >
<TextView
android:id="#+id/activityName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_toLeftOf="#+id/verticalLayout"
android:text="New Name"
android:textSize="25sp" />
<LinearLayout
android:id="#id/verticalLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:orientation="vertical" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="#+id/pound"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="2dp"
android:text="#"
android:textSize="20sp" />
<TextView
android:id="#+id/unit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:text="unit"
android:textSize="20sp" />
<TextView
android:id="#+id/slash"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="2dp"
android:text="/"
android:textSize="20sp" />
<TextView
android:id="#+id/number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Number"
android:textSize="20sp" />
</LinearLayout>
<TextView
android:id="#+id/date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:text="Date"
android:textSize="10sp" />
</LinearLayout>
</RelativeLayout>
Try putting the pound TextView & the date TextView inside a vertical LinearLayout, and then have the LinearLayout be aligned to center vertically and to the right.
Hope this helps :)
// try this
<?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:padding="5dp"
android:gravity="center">
<TextView
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="New Name"
android:id="#+id/activityName"
android:textSize="25dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#"
android:id="#+id/pound"
android:layout_marginRight="2dp"
android:textSize="20dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Number"
android:id="#+id/number"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:textSize="20dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="/"
android:id="#+id/slash"
android:layout_marginRight="5dp"
android:textSize="20dp" />
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:gravity="center"
android:layout_marginLeft="5dp"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="unit"
android:id="#+id/unit"
android:textSize="20dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Date"
android:id="#+id/date"
android:layout_marginTop="3dp"
android:textSize="10sp" />
</LinearLayout>
</LinearLayout>
If you have such problem in ListView make sure that you use proper inflation method. Parent view group must be specified for correct inflation.
mLayoutInflater.inflate(R.layout.listitem, parent, false);
Instead of
mLayoutInflater.inflate(R.layout.listitem, null);