Make First line height in textview the same as other lines - android

I have a recyclerview with bunch of textview each as an item as you see in picture below. (Blue lines aren't really there, i added them so you can see each item separately) as you can see everything seems nice and user will not notice the text is separated.
The problem is when user increases the line space(a typical option in app) line height gets bigger except the first and last line of each item and the result seems like second picture.
My question is how to find appropriate padding to set to each item so every line height seen exactly the same?
BTW i can not use just one textview for many reason!

You can increase the divider height of your listview according to linespacing height.
Or you can set an invisible view at the bottom of every row item and increase the height of this view according to linespacing height.
Or you can set padding at the bottom of every row item and increase the value of this padding according to linespacing height.

just add some padding to the parent of your textview in the layout file of your list item .
for example the layout with linearlayout would be like :
<LinearLayout ........
paddingTop=15dp>
<TextView
..........>
</TextView>
</LinearLayout>
and you could adjust the padding dynamically if you want.

Related

How to make recyclerview hight same as tallest item when multiline text present?

I am using recyclerview where item can have multiline text.the problem arise when one item has single line text and other has multiple lines of text.one item get bigger than other.
I want item height will be same as talles item.How i can achive this?
You can give fixed height to TextView. Like
android:layout_height="50dp"
Or you can set fix number of lines of TextView
android:lines="2"
This will help you inside your Textview tag in the listItem
android:maxLines="1"
android:marqueeRepeatLimit="4"
This will help text to scroll if its long engouh for one line

Android: AutoCompleteTextView top margin ListView

The AutoCompleteTextView displays a ListView in a popup for auto completion. On top of the popup, before the ListView begins, there ist a little margin, in effect the first line in ListView looks higher than the other entries. Is there a way to remove the margin. For me it is just a problem because a changed the "dropDownVerticalOffset" of the AutoCompleteTextView to be on bottom of the TextView, otherwise there is negative offset and you don't see the difference if height of the first line.
How can I remove this margin?
Try to add XML attribute to your AutoCompleteTextView:
android:popupBackground="color_what_you_want_to_background"
Hope, it helps you

How to get some space below my last list item alone- android

I have a list whose height is set to "fill parent". everything works fine but my last item in list touches the bottom of my screen. how can i get some space below my last list item.
You can add an empty view as footer: http://developer.android.com/reference/android/widget/ListView.html#addFooterView(android.view.View)
AFAIK there's no way to do that only with XML, you can declare the footer in XML and inflate, or create programmatically
Here is a 3-liner to add a spacer programmatically:
View listFooter = new View(this);
listFooter.setLayoutParams(new AbsListView.LayoutParams(AbsListView.LayoutParams.FILL_PARENT, 70)));
listView.addFooterView(listFooter);
uhmm.. seeing that you don't want padding, print a blank line (or transparent text) on a textview located after your listview. Or print a "extra" item on your listview.
you could use the Space widget
<android.support.v4.widget.Space
android:layout_width="match_parent"
android:layout_height="10dp"/>
can simply set the margin in the list ............
if need only bottom margin then use : android:layout_marginBottom=

Stretch the image dynamically depending on row height of listview

I have a row in a list view with 3 fields. Icon to the left, a header and a description about 3-4 lines below the header. Initially description is hidden. On click of the header the visibility is changed from Gone to Visible or vice versa. When the description is visible, I want to stretch image view (icon) to the height of the expanded row. How do I do this ? I have given
android:layout_height="fill_parent"
android:scaleType="fitXY" to <ImageView />
If I change, height of icon to LayoutParams.FILL_PARENT in the program, the images stretches more than necessary.
You can try using gravity's FILL, FILL_HORIZONTAL, and FILL_VERTICAL feature. Take a look a this for further detail on this.

Dynamically adjust the height of group headers in an ExpandableListView

I have an ExpandableListView (ELV) with the groups having LinearLayout. I have set the height of the group to some value (38dip in this case, equivalent to two lines of text). If the group heading is long and would take more than 2 lines, it is not shown properly in the ELV item - some part of the view gets scrolled. On the other hand, if I change android:layout_height to "wrap_content" in the LinearLayout, the groups always show all the lines. But the line widths are variable, i.e., short titles show up with only 1 line and long titles show up with 2, 3 or 4 lines. That looks ugly. I would like to implement the height to be something like max("38dip", "wrap_content"). Is there a way to do this?
Even programmatically, I do not seem to be getting the actual height of the group if I set android:layout_height to "wrap_content". Any suggestions there?
Could not solve the problem directly. Added the following to the xml layout file of the group:
android:paddingTop="7dip"
android:paddingBottom="7dip"
That makes the layout looking much less congested which is what I wanted to do in the first place. Moving on - but would be interested if someone else have a better solution.

Categories

Resources