I am working on a project that involves a letter filling up most of the height of the screen. At this point, the height of the letter is supposed to be 428 Pixels. The height of my screen is well over this, the layout (although a fragment) has ample room to fit the letter, and both the fragment layout and underlying layout are set to match_parent. For the textview itself, I have it centerInParent = true Trust me, I've been doing this a while so I know everything is correct as far as initialization goes, I just can't figure out why the letter wont appear! Oh, I should also note that although the screen can hold that size of a letter, it is tight (talking about approximately 50 pixels above and below), and that the entire activity and layout is set to a FullScreen theme, because I assumed it would give it more usable space. Any ideas? Thanks everyone!
EDIT: The total number of pixels I have in my display height of the monitor is 721, the letter takes up 428 pixels, after subtracting a few default-sized buttonss at the button that leaves me with about 260 pixels of free space. And as I mentioned there is no actionBar.
I found that I had to convert the textView using this code: txt.setLayerType(View.LAYER_TYPE_SOFTWARE, null); Hope this helps!
Related
I want that when my edittext is empty it's height is 40px, i.e., it takes space of only one line. And when text is typed the height increases. It should function more like the WRAP_CONTENT on its height, but I want that once it reaches the height of (5*40px) or 200px, i.e., space of 5 lines. It doesn't increases anymore. It acts as if it's height is fixed 200px. How can I access this type of height feature.
Please try to help by providing Programmatic reference rather than XML reference. Thanks in advance...
You should check this question out. It has exactly what you need. Next time while asking a question, please do a little bit research.
Set limitation for EditText height and Maximum lines
Also, there's a tag called android:maxLines="int"or editText.setMaxLines(int numOfLines) method if you want that to set how much the EditText will stretch. It'll do exactly what you need to do.
I have an ImageView, which is intended to take up the whole screen if it matters, and I intend to put several labels on it with TextViews. I need these labels to correspond to a precise position on the image.
I tried setting the margins in xml, but that won't work because the dp won't convert between devices. I am aware that I can set positions as a percentage of the screen size programatically but this poses a few problems:
I don't want to solve this problem programatically.
The aspect ratio of the image is being maintained, so on most screens there will be a little bit of white space given that the screen is a different shape from the image. Also, the app is not full screen, so the notification bar takes up space. This white space and the notification bar's space makes a percentage of the screen different from a percentage of the image.
How can i position TextView's on an ImageView in such a way that they will be in exactly the same spot (relative to the image) on every device?
I ended up figuring it out myself:
text.setX((int) (img.getX()+(img.getWidth()*pct)/100)
and the same for y, where text is the TextView, img is the ImageView, and pct is the location as a percentage of the image. Another problem is that this can't be called in onCreate(). I called it in onWindowFocusChanged().
To prevent your ImageView from being a different shape from the Image, which would break this solution, you can do:
android:adjustViewBounds="true"
and be sure to set at least one of the dimensions as wrap_content.
I have read all about supporting different screens and I understand the concept of Density Pixels (DP). However one thing I am not sure about. Lets say I have an image file which is 200 by 200 pixels and I loaded it using xml with wrap_content attributes at the top left of the screen (0,0). Now let's say I want to place a textview programmatically beside it.
If I put the text view at coordinates (250,0). Does that mean that the text view will never overlap the image and will always be to the right no matter what the device density/screen size is.
I understand the distance ( gap) will be different but I am hoping my theory of not overlapping will hold.
I tried it on 2 device and no issues but I am not sure if this is coincendence
Thanks
If you are using px unit it will always remain the same. But if you are using dp unit instead of pixel you cannot definitely be sure.
By the way you should use toRightOf property instead of this approach if you only want this.
I am creating an android app and I am having some trouble with the XML file. What I want is four ImageButtons displayed in the center of four quadrants of the layout (so one in each quadrant). I also want thees ImageButtons to be sized by a percent of the screen (so the button would be bigger on a bigger screen and smaller on a smaller screen) but to a maximum of a specific size.
description of what I have in the layout that works:
The layout that contains thees buttons takes up 70% of the screen height and maximum width (there is another layout in the top 30%) and the screen is locked in vertical orientation. so I'm only looking to complete this quadrant ImageButton style of view.
my attempts to accomplish this was:
1) grid layout: this wrapped my buttons up and they did not take up the whole screen or one quadrant filled up the whole screen and the other three quadrants were not visible.
2) layout dimension percent: several linear layouts positioned in vertical and horizontal orientation and using the layout_hight=0dp (or width), layout_weight="0.50" "trick" to position the quadrants out. This worked nicely but there is a warning i get that the layouts are inefficient when you use a percentage to size a layout within a layout that was position with a percentage, and the ImageButtons did not want to stop at a maximum size completely ignored maxHight & maxWidth (i did have adjustViewBounds="true").
3) I can make all this work easily by calculating sizes and positioning everything by code but I would really like to do this in the xml file and leave that as a last resort.
I would appreciate any help, even a push in the right direction would be grate. I have been stuck on this for a while thank you.
Just do it programatically. It's much simpler as xml is very static and java is dynamic and in complex situations easier to use. Save yourself the trouble.
I'm using the FontFitTextView that was posted in this other thread, but it isn't working exactly right for me. The measureText() call is returning a number that is obviously too small to display the string. When it runs through to find a font size that will allow the text to fit, the font size it settles on is still too big. I feel like there is some other kind of padding or margin or some other invisible that is contributing the math that makes up the width which is causing the discrepancy.
For example... I want to set the text of my FontFitTextView to be "10,000.25"
The width of my FontFitTextView is 96 pixels, with 8px padding on both sides, so my available width is 80 pixels. The call to measureText() says that the text "10,000.25" is 64 pixels wide. This means that the current font size should be small enough to display the entire string. However, when the string is actually drawn on the TextView the last 2 characters are chopped off and all I see is "10,000." instead of "10,000.25"
Any ideas?
It turns out the problem was related to the emulator. I provisioned my app to my android device and the FontFitTextView worked as intended.