Background for item RecyclerView - android

For the RecyclerView elements I use CardView. I would like to make each item of the list
A background image is not a problem to prepare. I do not specify the size of the CardView, I have specified match_parent and wrap_content. I do not know what size to make a background image, so that it looks fine on the phones and on the tablets.
Any suggestions? Or do I need to specify the width and height of the item for phones and tablets and already do the background for them? How do experienced developers? vector drawable is not interested yet

To create resizable images you should check out 9-patch. It's the easiest way to fit the image to different ratios. Here you can find a post that better explains how to use it.
To create the image you can either use an online tool, or use the tool provided in Android Studio.

Related

how to maintain the Image Position and Size for all size of Devices in android?

I have layout like below image and I have designed using image view and image button for this images. while run for other devices its alignment and size is Varies:
so Which layout want to use
Size based on design or device based or
any technique is there for the responsive design
**i'm using only on Landscape mode
There is a few ways to do this.
The easiest way is to use androids grid layout and build it that way,
this takes a bit of getting used to but it works well.
the 2nd way is to make alot of values folders and ajusting dimens in them:
https://developer.android.com/guide/practices/screens_support.html

Android 9 patch images used for

I am having an question regarding 9-patch images in android.
Do we use these 9-patch images only for background purpose or we have some other use of these 9 patches.
I found we use these images in buttons background.
Can anyone suggest excluding buttons where i can use these images.
Thanks.
You can use 9-patch images anywhere as long as it fits your layout purpose. For me, I use 9-patch if i found that the image can "repeat itself somewhere inside".
I use it as divider between two views, view backgrounds, or simply an image itself since I can specify which part it should extend.
We can use specially for multiple screen which is adjustable in any screen size of device.
Here is site to create the 9-patch images.
http://android-ui-utils.googlecode.com/hg/asset-studio/dist/nine-patches.html
I use 9-patches to set the background of ANY view doesn't have a fixed weight/height; usually, because of its content has variable size (i.e. it contains a TextView with variable number of lines)
This applies to any kind of view, custom dialogs, buttons, ...

Android layout difficulties - dynamic control of parameters and content. Best way to code?

I am attempting to make an 8x8 matrix of coloured squares on a black background in a layout that is limited to portrait only. I need the squares to all be equal in size, and the overall matrix to be 60% of the screen's width and of equal height. I also need to control the colour of each square dynamically as a result of my code, call it a pattern setting code if you will. Here is an example of what I need the final product to look like:
Screen example
I have been researching different ways of doing this and was hoping for some advice on the best approach. Here are some ideas I had:
1) Use GridLayout (not GridView) and set the background of each cell to the required colour. This shouldn't be difficult to control with java, but how do I enforce the correct dimensions? Would I need to fill each grid cell with something of a certain size, or can I use layout_weight attributes to control the dimensions?
2) Use a combination of RelativeLayout and LinearLayout with ImageView and display locally saved images of coloured squares. Can I use layout_weight to control the size of these images, and if these images were too small would they be stretched to fill their required dimensions? (I'm thinking of larger tablet screens.)
What I really need from someone is some sample code to implement a very simple version of what I need (for example one square in the centre of the screen that I can colour-control dynamically). Obviously I can then expand it to my specific requirements. If more details or code are required I will happily post them.
Perhaps you could just create a custom View object, and render the appropriate bitmap in the onDraw method? Seems like overkill to use layout objects, unless you're planning to do more than just render squares of colour?
Edit: Alternatively, I once used the info in the following posting to programmatically build a layout grid. It's not exactly what you need (it generates as many horizontal 'cells' as are necessary), but should make for insightful reading on manipulating layout dimensions:
Line-breaking widget layout for Android

Android... positioning components accurately over background image

I want my app to run on a wide variety of android devices in portrait only. I have a whole-screen background image that includes borders for other components. I want to place items like listviews/sponsor ads accurately within those borders... overlay them on top of the background in exactly the right place. Is using Framelayout the best/easiest way to do this? How do I make sure I get the listviews or sponsor ads in exactly the right place, and exactly the right size given that the background will be stretched to different dimensions for different devices? I've considered cutting up the background image instead but that seems like more work. What's the best approach? Thanks for any thoughts!
Unfortunately, this scheme is never going to work consistently across all screen sizes. If you want borders, you need to create 9-patch graphics out of those and assigne them as teh background to the UI item.

How to design ImageViews that stretch according to the screen-size

I have a requirement where few of my image views form border areas of an application, and the application will be running on many screen sizes.
I'll be creating a uniform image for the smallest size possible, which can be repeated as many times as needed, and still presents the same image.
I want the image view to replicate the image contained whenever it is increased.
Is anything like this possible?
I tried 9-patch images, but I couldn't find nice articles on it which could explain how to create useful images with it which could suit my need.
I think you have to write a custom view to do this. Overide onDraw method in it to copy your bitmap as many times as needed.
Get the width and height of the device dynamically and set the imageview width and height in program.

Categories

Resources