Android. Textview. Dot sign is taking too much space - android

I am using custom(Gotham Light) font. Textview contains date where numbers were divided by dot(.).
<TextView
android:id="#+id/tvDateFrom"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="12.06.14"
android:textColor="#color/white"
android:textSize="12sp" />
Dot sign is taking too much space.
How to make dot take only the space it needs?

Take a look at documentation : public void setTextScaleX (float size)
Sets the extent by which text should be stretched horizontally.

you need to use this attribute android:textScaleX in your xml file
add it like this
android:textScaleX="0.1"

You can use
android:textScaleX
or different text font
android:typeface="sans"

It looks like that you have a problem with your font - Gotham Light. First of all - try some other font. But if you are attached to Gotham - consider checking your text formatting - try dot unicode symbols, for example: \u002E

Related

TextView with 3 lines has different height depending on amount of filled lines

I have the following TextView:
<com.mycompany.CustomTextView
android:id="#+id/productName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:lines="3"
android:maxLines="3" />
This results in an expected look of the TextView with different amounts of text:
However, when I use our corporate font created by our company, the TextView is getting bigger with every line with no text:
I don't know how this can be dependent on the used font. Is there any attribute in the .ttf file that leads to this odd behaviour?
My first thought was that Android adds new paragraphs to the TextView if not all of the lines are filled. But it would be new to me that a font file can define a default paragraph spacing.
As your view has height and width as "wrap_content" with max_lines = 3. Now it's quite obvious that view's dimensions will change depending as it will figure it out that how much height it will need to accommodate three lines of specific type (font) of input text
As you have custom Textview.Calculate and update LayoutParams dynamically based on the aggregate height of each line.
Yes Text size will vary based on font types.
Check this for detail explanation.
Vote if it helps.
Thanks. Happy coding.

Can I scale the actual text in a TextView in Android?

Is it possible to create a scaled TextView like this where the text itself is scaled in one direction? In the picture, the top half shows a basic TextView outlined in blue. The bottom half shows the same TextView after the scaling I'm trying to do. The height is the same but the width of the view has been cut in half.
I don't think that this is possible with a TextView using the default font. To accomplish the effect you are looking for you would probably have better luck creating and resizing an image or dynamically using a different font that has half the width per character.
I personally use the library autofittextview from grantland in my projects.
The usage is simple.
<me.grantland.widget.AutofitTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:maxLines="2"
android:textSize="40sp"
autofit:minTextSize="16sp"
/>
for example. The result is as follows.

How can i set axis unit label?

I'm using android graphview 3.1.1. I am trying to set an axis label, a label identifying what the axis is.
The only thing I've found close to this in Android GraphView is setting individual tick-mark labels as withgraphView.setHorizontalLabels(horlabels). Is it possible to set the entire label?
Example here, the axis labels are Month and Weight in Kg.
I have had a similar problem, so I set a by -90° rotated TextView beside my LinearLayout where i draw the graph.
<TextView
android:layout_height="fill_parent"
android:layout_width="wrap_content"
android:id="#+id/test"
android:textColor="#FFFFFF"
android:gravity="center"
android:rotation="-90"
android:textSize="12dp"
android:text="°C"/>
The problem with this method: The width of my rotated TextView stays the same like if's not rotated. So there is a huge amount of space to the left and right if you use a long text. If you shorten the layout_widht there is a line break.
For short text it looks nice: http://i.stack.imgur.com/KWMk8.jpg
there is no build-in feature for that, but you can achieve this by nesting the GraphView-View in layouts with TextViews
There are no ways provided to set the entire label. You may have to do this with TextViews.

Is there a way to perfectly center text?

I wanted to know if it was possible to create a custom TextView that centers text perfectly, no matter what the font is. That's my major issue right now, but I'm also wondering if it's possible to set the specific height using pixels so that the height would also be consistent.
This picture shows how different fonts are sized and centered. The longest black line in the picture is the middle of the white space. Letters in the picture are the same in every way except for the fonts. The text size is the same (text.setTextSize(TypedValue.COMPLEX_UNIT_PX, 450);), and they're all centered. I hope someone knows the answer to these questions! If you need any code from my app, just ask. Thanks!
EDIT: I am aware of android:gravity="veritcal_center", but that only works to an extent. What you see above is that implemented in the textview, but each font has a different center of gravity, so android:gravity="veritcal_center" wouldn't really make all of these center perfectly along the screen. I'm looking for a way to create a custom textView that somehow measures the height of text and centers it with those parameters. A suggestion by #vmironov in the comments works, but only if the textview has one character. I have not been able to mess around with his code, but I will when I get a chance and I'll post here if I find anything. Thanks!
A simple way to achieve what you want is to use following code:
<LinearLayout
android:layout_width="100dp"
android:layout_height="20dp"
android:gravity="center">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18sp"
android:text="#string/your_text" />
</LinearLayout>
set the height and width values of LinearLayout fixed if you want to set the text to be alligned in center within constant height and width
Set the gravity of the view to "center_vertical". Something like :
android:gravity="center_vertical"
You should be able to center your text by applying a gravity attribute to the containing TextView.
In XML you would assign an attribute to your TextView, which would look like this:
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:textSize="18sp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/some_text" />
If you do want to specify a particular size for your text, it is strongly suggested you use SP (Scaled Pixels) as your unit of measurement, and not Pixels. You could also set an Appearance Attribute for your TextView to control the size, which is also shown in the code example.

Custom typeface text size varies greatly between fonts

I have a few TextViews in my app where I use a custom typeface. I have given the view centered layout gravity to get the text centered in its parent layout. It looks fine in the previewer with the Sans font, but when I change the typeface, the result looks like the text is shifted down, like this:
Compared to this:
Here is the xml for that element:
<FrameLayout android:id="#+id/Turn_ScoreA_Frame" android:padding="5dp" android:background="#color/teamA_secondary" android:layout_margin="5dp" android:layout_gravity="center" android:layout_height="50dp" android:layout_width="110dp">
<android.view.View android:id="#+id/Turn_ScoreABG" android:background="#color/teamA_primary" android:layout_height="fill_parent" android:layout_width="fill_parent"></android.view.View>
<TextView android:id="#+id/Turn_ScoreA" android:includeFontPadding="false" android:text="5" android:layout_gravity="center" android:layout_height="wrap_content" android:layout_width="wrap_content" android:textSize="32dp"></TextView>
</FrameLayout>
This also occurs when I use fill_parent for layout_width and height of the text view, with text gravity center. I set the custom Typeface in the OnCreate of the view in which this layout is used, just by using TextView.SetTypeface.
Does anyone know what could be causing this? I'm having trouble tracking anything down on this.
As a note, I've worked around this on several views by setting the margin_bottom to -10dp or so, but I'd like to remove that, and I can't get that hack to work on confined views like this one, anyways.
The font is Anton, by the way.
EDIT: This is definitely the result of the text being too large for its container. The thing is, Sans fits just fine, and the new font would fit but its measured size is too large. What I'm hoping is to find a way to get the text to remain at its current visible size and fit in the center of the container, in such a way that doesn't feel too hacky =)
You need to add:
android:includeFontPadding="false"
You have 3 options
Decrease the text size
Increase the height of FrameLayout
Change the font which can fit correctly
you cannot change the property of the font, it is designed is such a way that it has empty space above it, which doesn't fit in your given android:layout_height="50dp" when android:textSize="32dp"

Categories

Resources