Stretch the image dynamically depending on row height of listview - android

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.

Related

Scroll on recycler view and make a text view move with a specific item in the recycler view while text could be longer than the width of a item view

I have a horizontal recycler view and have items in it. Now, I want to add a title, which could be pretty long, above a specific item. When scrolling, I want that text view move along with that item while the text could be pretty long and exceed the item's layout. Is it possible?
Use textView with fixed width and apply autosize xml attribute the the text will auto resize according to the length of the text/
<TextView
android:layout_width="match_parent"
android:layout_height="200dp"
app:autoSizeTextType="uniform" />

Make First line height in textview the same as other lines

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.

Can I display a textview that overlaps it's parent ViewGroup

I have a horizontalScrollView with a listview in it. I add multiple custom RelativeLayouts to this, each one contains two TextViews, vertically.
The top TextView will always be visible and will have a small amount of text, things like S,M,L,XL,XXL.
The bottom TextView will only display when the top one is selected. The text in this will be much bigger though, e.g. Low in Stock, Out of Stock etc.
Because the bottom TextView is bigger, it is forcing the gap between each RelativeLayout to be different depending on the text in the bottom TextView.
I would like the distance to be equal between each RelativeLayout and as there will only ever be one bottom TextView visible at one time, I would like that text to potentially span beneath multiple top TextViews.
Is this possible? At the moment, I can't find anything that will help.
I have included an image. The top is what I have, with the bottom TextView size dictating the overall space. The bottom image is what I'd like, with the bottom Text overflowing beneath the top Text when it needs to.
UPDATE: #mikejonesguy, roughly what I have is (psuedocode)
<Relative Layout>
<TextView
android:id="#+id/id1"/>
<TextView
android:layout_below="#id/id1"/>
</Relative Layout>

how to make the change the background when ListView is Scroll up

i am trying to implement ListView. Problem is that when i am showing items of list less that the scree size the remaining is showing black. I want to set any image so that when items are less than screen size then background should be a picture
put your <ListView /> inside <LinearLayout/> ,
add background to Linear layout, with LL Height as match_parent and hieght of Listview as wrap_content
I have not done this myself, but this is what I think should work.
Place the image in /res/drawable
Then add these lines to activity in manifest or to parent layout of ListView
android:scaleType="fitCenter"
android:background="#drawable/image_name"
Let me know how that goes.

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=

Categories

Resources