Text View Above overrides Text View below it - android

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>

Related

How to prevent truncation in RelativeLayout

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.

How set Text Align?

I want TextView to end at red Line in picture below instead of start line of three blue textviews .
How ?
layout.xml
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="49dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentBottom="true"
android:layout_margin="20dp"
android:id="#+id/relative">
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:background="#drawable/progress"
android:id="#+id/imageView"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="50dp"
android:text="Progress"
android:id="#+id/textView"
android:autoText="false"
android:textColor="#1A237E"
android:textSize="#dimen/abc_dialog_padding_top_material"
android:layout_alignParentTop="true"
android:layout_toRightOf="#+id/textView2"
android:layout_toEndOf="#+id/textView2"
android:gravity="center" />
<TextView
android:layout_width="wrap_content"
android:layout_height="30dp"
android:text=" absolute"
android:id="#+id/textView2"
android:textIsSelectable="true"
android:textSize="#dimen/abc_action_bar_icon_vertical_padding_material"
android:textColor="#FF6D00"
android:gravity="center"
android:layout_alignBottom="#+id/above"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/above"
android:paddingBottom="10dp"
android:background="#ffd8f1ff"
android:padding="5dp"
android:layout_below="#+id/textView"
android:layout_alignRight="#+id/textView"
android:layout_alignEnd="#+id/textView"
android:layout_gravity="right"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="30dp"
android:text=" percentage"
android:id="#+id/textView4"
android:textSize="#dimen/abc_action_bar_icon_vertical_padding_material"
android:textColor="#FF6D00"
android:gravity="center"
android:layout_below="#+id/textView2"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/below"
android:paddingTop="10dp"
android:background="#ffd8f1ff"
android:padding="5dp"
android:layout_below="#+id/above"
android:layout_alignLeft="#+id/above"
android:layout_alignStart="#+id/above"
android:layout_gravity="right" />
<TextView
android:layout_width="wrap_content"
android:layout_height="30dp"
android:text=" goal"
android:id="#+id/textView5"
android:textSize="#dimen/abc_action_bar_icon_vertical_padding_material"
android:textColor="#FF6D00"
android:gravity="center"
android:layout_below="#+id/textView4"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/goal"
android:paddingTop="10dp"
android:background="#ffd8f1ff"
android:padding="5dp"
android:layout_below="#+id/below"
android:layout_alignLeft="#+id/below"
android:layout_gravity="right"
android:layout_alignParentLeft="false" />
thanx in advance .
First, right align your three blue TextViews with the Progress TextView. That way, all the blue TextViews will be right aligned. Then, instead of using layout_gravity=right, use gravity=right. That will right align the text within the blue TextViews. Finally, make all the blue TextViews be to_rightOf textview4, which is the longest TextView. Doing these adjustments will make the layout look like this:
Here's the code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:id="#+id/relative"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_margin="20dp"
android:layout_marginTop="49dp">
<ImageView
android:id="#+id/imageView"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"/>
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_alignParentTop="true"
android:layout_toEndOf="#+id/textView2"
android:layout_toRightOf="#+id/textView2"
android:autoText="false"
android:gravity="center"
android:text="Progress"
android:textColor="#1A237E"
android:textSize="#dimen/abc_dialog_padding_top_material"/>
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_alignBottom="#+id/above"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:gravity="center"
android:text=" absolute"
android:textColor="#FF6D00"
android:textIsSelectable="true"
android:textSize="#dimen/abc_action_bar_icon_vertical_padding_material"/>
<TextView
android:id="#+id/above"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignEnd="#+id/textView"
android:layout_alignRight="#+id/textView"
android:layout_below="#+id/textView"
android:layout_marginLeft="5dp"
android:layout_toRightOf="#+id/textView4"
android:background="#ffd8f1ff"
android:gravity="right"
android:padding="5dp"
android:paddingBottom="10dp"
android:text="18%"
/>
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/textView2"
android:gravity="center"
android:text=" percentage"
android:textColor="#FF6D00"
android:textSize="#dimen/abc_action_bar_icon_vertical_padding_material"/>
<TextView
android:id="#+id/below"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/above"
android:layout_alignRight="#+id/textView"
android:layout_alignStart="#+id/above"
android:layout_below="#+id/above"
android:background="#ffd8f1ff"
android:padding="5dp"
android:paddingTop="10dp"
android:text="12.4%"
/>
<TextView
android:id="#+id/textView5"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/textView4"
android:gravity="center"
android:text=" goal"
android:textColor="#FF6D00"
android:textSize="#dimen/abc_action_bar_icon_vertical_padding_material"/>
<TextView
android:id="#+id/goal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/below"
android:layout_alignParentLeft="false"
android:layout_alignRight="#id/textView"
android:layout_below="#+id/below"
android:background="#ffd8f1ff"
android:gravity="right"
android:padding="5dp"
android:paddingTop="10dp"
android:text="0%"/>
Instead you can put those two horizontal TextView inside a
LinearLayout and set the LinearLayout below the percentage's TextView. Doing this you can have more customizability with the alignment of the TextView.
In your case this was different than what I normally set it up. But in this case its easier to add
<View
android:layout_width="0dp"
android:layout_alignRight="#+id/textView"
android:layout_alignEnd="#+id/textView"
android:id="#+id/holder"
android:layout_height="0dp"/>
and then for the views you want to align to the right side add
android:layout_toLeftOf="#+id/holder"

Android ScrollView not working properly

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.

RelativeLayout layout_below issue in android

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);

how to align text view in between two images

my text view not align on center below is my code this is my scren shot
i just want to align text view center of screen help me please
<RelativeLayout
android:id="#+id/lytTitlebar"
android:layout_width="fill_parent"
android:layout_height="45dp"
android:background="#drawable/border"
android:layout_alignParentTop="true">
<ImageButton
android:id="#+id/imgNavBack"
android:layout_width="wrap_content"
android:layout_height="45dp"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:src="#drawable/nav_back"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"/>
<TextView
android:id="#+id/txtTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18sp"
android:textStyle="bold"
android:textColor="#color/text"
android:text="#string/category_list"
android:layout_toRightOf="#+id/imgNavBack"
android:layout_centerVertical="true"/>
<ImageButton
android:id="#+id/imgRefresh"
android:layout_width="wrap_content"
android:layout_height="45dp"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:src="#drawable/refresh"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"/>
</RelativeLayout>
Try this:
<TextView
android:id="#+id/txtTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="18sp"
android:textStyle="bold"
android:textColor="#color/text"
android:text="#string/category_list"
android:gravity="center"
android:layout_toRightOf="#+id/imgNavBack"
android:layout_toLeftOf="#+id/imgRefresh"
android:layout_centerVertical="true"/>
Just copy layout and replace with your icon it will work.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#ff4444" >
<Button
android:id="#+id/header_toogel_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:background="#drawable/ic_launcher" />
<Button
android:id="#+id/header_search_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:background="#drawable/ic_launcher" />
<TextView
android:id="#+id/sub_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="Your Text Will Be Here"
android:textAppearance="?android:attr/textAppearanceLarge" />
</RelativeLayout>
You should use both for textview
android:layout_centerVertical="true"
and
android:layout_centerHorizontical="true"
or
you can use
android:layout_centerInParent="true"

Categories

Resources