Android TextView line background - java

I'd like to create a textview that contains a blue line as it's background just like in the image I provided. You can also find it in Google calendar when entering appointment info.
I previously tried using 9patch images to stretch the line horizontally and keep the vertical scaling the same. But that does not work. I'd like to also use this in other view to provide my own background to other views. Any hints?
Thanks you in advance!

I believe that you are looking for the EditText layout item, not TextView. It will automatically change the line to the blue color when the user places the cursor there, otherwise it will be black.

you can use a relativelayout for your edittext, and for the lines, a view 1dp high at it's bottom (width matchparent so it stretches) , and two 1dp wide views at its sides, that'd accomplish that effect (as high as you want them).

Related

Android: list jumps to other post when scrolling because ImageView height is wrap_content

I have a list which contains posts that each contain one image. The ImageView width is set to match_parent, so it's always the same. Thee ImageView height is set to wrap_content, so the image height is not always the same. The last thing is what causes a problem with scrolling, because I'm also using Glide. The system doesn't know how far it has to scroll until Glide loads the picture, gets the dimensions of it and then resizes the ImageView. When the picture is done loading and the ImageView height is set, the list "jumps" and the screen shows another post. This is solved when wrap_content is replaced by a fixed value, but this is not what I want, because in that case there's a lot of empty space around the picture for some images.
Is there any other way to achieve what I want?
Edit: the solution works, but it was still not what we wanted to achieve. We ended up changing the JSON. It now shows a ratio as well, with which the size of the ImageView can be calculated before the picture is loaded. This way the ImageView has a fixed size anyway, but it's an individual fixed size.
Check out Glide.with.pauseRequests:
if you call Glide.with(fragment/activity).pauseRequests(), new
requests will not run until you make a corresponding resumeRequests()
call. Those changes let you add an OnScrollListener and pause/resume
requests depending on the scroll state.

How to define a clickable area in an image used in ImageView

Is there a way to define a clickable area in an image? Something equivalent or similar to map-area tags in HTML? Or is there a standard way of doing this sort of thing?
A possible method
1) get the width, and height of the image view using (in pixels)
2) get the coordinates of the image view (which is the top left corner of the image view)
3) create a touch listener, and record the coordinates of the users touch
4) if the user's touch coordinates fall on the image do whatever you want to
If you only want to do certain things based on where the user touches you will have to calculate the coordinates of those regions using the coordinates of the image view, and the image views width and height.
I think there might be no standard way for this, but you can achieve it by placing a transparent VIEW over your imageview. Set click listener to that view and make imageview clickable false.
When i have to do something similar, i use an include view.
As for the layout the include view will be accessing, i would use FrameLayout as root.
Its children would be the ImageView that i want to depict, along with a LinearLayout infront of it containing Buttons at the positions i want the user to choose from.
Then in code, i set listeners to these buttons.
Lastly, i would set the buttons so that there background is transparent and text is not available.
For example in a project i am working on, i have an ImageView with an Image of Ocean as background.
In front of the view i have a LinearLayout with smaller ImageViews with images of islands.
I place listener on the islands to see when they are clicked to open a new activity.

Fading overlay through FrameLayout foreground with specified Rect that cuts out a section of the fade

Goal: A highlighted section of an image (the image covers the whole screen). The rest of the screen needs to be faded out.
Example
So far I've got the fading working using the foreground of a FrameLayout and placing the image as the background of a RelativeLayout within the FrameLayout. The solution I'm thinking is that I need to create 2 Drawables and merge them into one that FrameLayout Foreground can consume.
I've also been reading a bit up on PorterDuff, but I think that may be overkill for what I'm trying to achieve.
The fade functionality is working fine, but the source of the fade with transparent section is not.
I suggest that you have the original image in an ImageView on top of it place 4 views which are partially dimmed and that's it!
With some basic math you can know the sizes for each view, and using RelativeLayout will allow you to easily place them on the screen.
Good Luck!
P.S. I've attached a sketch to illustrate what I'm suggesting.

Image that has multi clickable zones/surface/area

I want to have an image on the android screen where different parts of the image can be clickable. What I mean is that, If its an image of 3 circles, I want to be able to click each of these circles,
Then I can add different functionalities to each of these clickable circles.
For an instance in this image below I want to be able to click each distinct color. Is it possible to have on-touch-listener and get you the color ? and can it be an image or has to be drawn in Java OR XML ?
I found a really good widget that helps you make any image muli-clickable. They have some good notes on how to use their widget as well.
The widget has a similar approach as Image mapping in html. The good thing about this widget is that the image can be zoomed and it will not lose the coordinates or areas associated to specific clicks.
Here is the link to their website. the guy who made the widget apparently had similar problem and came up with this widget.
Another solution would have been
creating an ImageView containing the png file referenced
making the whole ImageView clickable
setting an OnTouchListener to the ImageView which overrides the onTouch method
check the colors of the image pixel at the touch position
This is often done with an invisible mask image with one color for each zone (see the popular detailed tutorial), but here the image itself has distinct colors for each zone which makes it more interesting.

Android border layout with an EditText overlapping on it

I want to code a layout like the following image in xml in Android.
One approach would be to have a RelativeLayout and make a 9 patch rounded rectangle border image, have it as the background around a layout which has the two blue buttons, and then have and EditText overlapping it, with its background set to a red color.
What could be other approaches?
As I understood your question you want to make series of photos ..like Gallery application
you can do it with more option also.
1)this is gallery type application .
so . you can use this basic code :Android Gallery Application
2)If you want to see all the photos in circle this is also possible..
It depends upon your need ..please write in brief you want more...

Categories

Resources