I have this scenario:
An activity with a global layout that has a background image that fills it up.
In such image (provided by designer) there is a white box where some text is supposed to be printed with information from the app at runtime.
We are having problems to understand how we can print in the same position regardless of screen resolution and density... Whenever we change the tablet we get wrong positions for the text...
Any hints?.
Thanks in advance
The best way to do this is to ask the designer to break out the box from the image, and then you aren't worried about the exact nuance of image placement.
Okay, so what if that's not an option? This is where you have to go pixel counting. I would recommend you do the following:
Devote an entire class to getting the text right. This class should extend View, or one of it's subclasses.
In the class, you can determine the size of the image, but not at onCreate. You'll have to determine this in a custom View onMeasure.
This class will have to figure out how to stretch the image appropriately, and based on how it's stretched, figure out where the text box should go.
Hopefully this is enough to get a start on it.
Related
I am trying to replicate the below layout (Boxes with Text and a line going outwards on a dedicated section) on Android
As evident, these boxes can be implemented as individual views (or drawable) to have the shape as
.
It is apparent that these boxes need to have some flexibility for the "wires" going out of them, most importantly deciding the "turning" point of the line. I have thought of a few approaches to achieve this:
Achieve the entire layout just by using image drawable and positioning the text boxes at exact places
Implement this with a dedicated view to have full flexibility of positioning the text boxes at any position and be compatible with all screen sizes.
I am inclined towards trying #2, but can't get my head around where to start. At first, I am not able to decide on whether I should be using a ViewGroup as the base class and add a TextView and a plain view as a child or should I be using a single View to implement this? The second thing I am concerned about, is whether I am overthinking it and there is an easy way to achieve the same thing (Just to save time, nothing else)?
Any help/guiding material is deeply appreciated. Thanks in advance.
I think that approach #2 will be better longer term. Because of the nature of the image, you will have to maintain the aspect ratio; otherwise, the person is stretched. Because you are maintaining the aspect ratio (at least the person-part), the placement of each text box and end point can be expressed as a percentage distance from an edge or the center lines.
Assuming the image you show is the entire image, the belly end point can be set at, say, 45% of of distance from the left edge and, also let's say, 42% of the distance from the top. The text boxes can be placed likewise. Once the text boxes and end point are place, the lines simply connect them. Now the image can stretch to any size to support multiple screen sizes and, as long as the aspect ratio is respected, and look good.
Take a look at ConstraintLayout and its percentage guidelines and barriers. There is also some radial placement which may help. You may still have to support the layout with a little code, but ConstraintLayout should be able to get you 95% of the way to a solution.
Edit: I meant to mention biases as well which may be the most helpful to you. Here is an example of using biases for a checkerboard solution that may be useful.
I need to create the markups on image view that should look like the markings Instagram. The client should click on some position on the image, enter some text and save it.
For now, the only solution that I see is :
Get click position in the onToch event.
Dynamically put some edit boxes to this position.
Save the text and coordinates.
However, I don't know yet how this will work on different screen sizes.
Since I'm mostly web developer and definitely don't now all android capabilities I hope someone with experience will give me advice. Maybe there some widgets for this task, or algorithm for counting position?
I am working on an application in which I am using a frame layout. In the frame layout there are three classes as follows:
creating image
checking the pixel of the image the user touches
drawing the image
But when I am touching on the same color, it is giving me a different color value. If anyone wants to see my code then it is there. If you want to check which image is used by me then the images are as follows:
the second image which is used for getting the pixel:
Can any one tell me why it is not giving me correct value of the color on touch on the image
?
Edited1
my edited code of the imagein class is as follow [code after editing4
My guess is that you are making assumptions based on the the pixel coordinates of the image, and not translating the coordinates as they exist once Android resizes your art. You should see what Android thinks the image size is, after it's drawn to your View and make sure that the spot you're touching is the same spot that you're expecting to be touching.
I'm trying to use a custom font with the text in my Widget. Since the RemoveViews is very limited and doesn't support custom fonts in the TextView options, I found this post that showed a clever way of getting around this. Essentially, instead of using a TextView I use an ImageView and render a bitmap of the text in the custom font and set the ImageView's bitmap to the rendered image. Now the only problem is that I need to determine the width to render the Bitmap so it fits perfect in the fill_parent on the ImageView. So how do I get the width of a widget?
I'm trying to use a custom font with the text in my Widget.
Note that the correct term is "app widgets". Widgets are subclasses of View. App widgets are the things that go on the home screen. See: http://developer.android.com/guide/topics/appwidgets/index.html
So how do I get the width of a widget?
You don't. You know what you asked for via your metadata. What you wind up with is up to the home screen implementation, and there is no way to retrieve that information. That goes double for widgets that the user resizes, either because you indicated that you support resizing, or the home screen just decided to roll that feature themselves.
I am fairly new to android and am having some problems with a layout. Below is an approximation of what I want the layout to look like. (I would like the list to be below the screen at first so that the user can scroll down to see it.) However my code as it currently stands makes all of the views on the left only take up a quarter the screen instead of half, as depicted, even though I have all widths set to fill_parent.
Also, this layout seems to mess up the coordinate system on my custom view. Normally this wouldn't be much of an issue, but in this case I am using that view to draw a picture and the picture ends up in the wrong place. Does anybody have any idea how to resolve these issues?
Could you show the XML file you are using? This would be helpful. Also, the coordinate system of a View does not change based on the layout.