How to handle RecyclerView items of different sizes - android

I have a recyclerView with an adapter inflated inside a cardview. Each item in my list has a different size, because of different image sizes. I am facing visibility problem as cards get recycled, in my cardviews as shown:
How can I fix this problem?
[EDIT] My CardView layout: https://drive.google.com/file/d/1zdM5H54CtfxZBxk6x72uYnSbCzxCnT-_/view?usp=sharing

In your <ImageView> you need to add scaletype property for it. Add it like below
<ImageView
.......
android:scaleType="CENTER_INSIDE" >
It will change the ratio of your image but full image is visible. fitxy also visible whole image as well. Choose more suitable one according to your needs
You can see a good example here. https://robots.thoughtbot.com/android-imageview-scaletype-a-visual-guide find out what scale y=type you want and add it.

As Lucifer said:
In your you need to add scaletype property for it
If you don't like center inside you can use CENTER_CROP or try anyone of the options.

Related

how to have recyclerview horizontal imageview share a side like a carousel

I have a recyclerview set up with a linear layout at horizontal where each imageview takes up the full width of the visible recyclerview. I was wondering how to fix this such that the imageview items are next to each other the way you'd see this in a carousel. A copy of what I'm seeing is found below. Thanks!
In your layout item, which you are inflating using the adapter class.. you should define the width of the layout as either wrap_content or a fixed value(for eg: 200dp or something else according to your need). I think you have used match_parent that's why you are facing such an issue.
Feel free to ask if something is unclear.
Looks like the ImageView has been resized based on the layout_height specified and you have a value of wrap_content on the layout_width. You should set the ImageView's attribute android:adjustViewBounds to true.
Reference: https://developer.android.com/reference/android/widget/ImageView#attr_android:adjustViewBounds

How to make each row of android listview a trapezium instead of ractangle?

I want to customize my listview to achieve this design,are there any library available for this?what can be best way to achieve this.Are there any disadvantage with such designs.
Thanks,
You can achieve this in two different ways
add an image instead of divider containing these tilt lines you can do this by using a simple line of code in your layout or in your class
android:divider="#drawable/divider_image"
or you can change it in you java class like this
list.setDivider(R.drawable.divider_image);
the second way of achieving this is you set a static image in you item layout below the item and change it according to your need as if the item is odd set a different image and if the item is even set a different image
<ImageView
android:id="#+id/imageViewDivider"
android:src="#drawable/divider_image"
android:scaleType="fitXY" />
and change the image in java class
ImageView imageView = (ImageView) findViewById(R.id.imageViewDivider);
imageView.setImageResource(R.drawable.divider_image);

Align a layout top of a image that is centered

I have a relative layout, inside of it is a ImageView that is centered in its parent.
I want to add a share up to the image. If I put this attribute android:layout_alignTop="#+id/myImage" the button will appear over the image. I want to be upper than this.
Use
android:layout_below="#+id/shareId"
in your <ImageView> tag. Or
android:layout_above="#+id/myImage"
in your share's View tag depending on what works better for you. If this doesn't fix it then please post the xml and a picture of what you want/have if possible.
RelativeLayout Docs shows the different properties that can be used.

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.

Constrain the height of RelativeLayout to specific child view

I there a way to wrap_content on a specific element inside of a parent element? For instance, I have something like the following layout:
<RelativeLayout width:match height:wrap>
<ImageView width:match height:wrap scale:fitXY />
<LinearLayout width:wrap height:wrap>
</RelativeLayout>
The parent wrap constraint is very loose, but I want it to specifically use the matching width, but always match the height of the image view.
The problem here arises when I place this view in another RelativeLayout where each view is aligned above or below another in order to fill a potentially changing superview. LinearLayout didn't really seem to stretch things to fill, so I switched to Relative, but when I did, the view described above stretched vertically when I want it to still match the height of the image view.
Is there a good solution to this problem?
You could try putting the following (pseudocode) in the onResume() method:
if(myRelativeLayout.height > myImageView.height)
myRelativeLayout.setHeight(myImageView.height);
You need to make sure to call myRelativeLayout.measure() before you do this, so the system knows what the size of the Views will be.
Just an idea for you to try, let me know if it works :)

Categories

Resources