Scrollable textview text turns black - android

I am currently developing an electronic guide for Latvian traveler. I have a scrollable 'textview' which is going to show information about object which is selected. So the problem is when i touch the text and start to scroll it is looking like this good
but when i touch it a little longer it turns black and after i scroll it for three lines text color is white again.bad
So the question is how to make it stay white on longpress or where the problem could be?
My textviews code:
<TextView
android:id="#+id/textView2"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/imageView1"
android:layout_below="#+id/imageView1"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:maxLines="5"
android:scrollbars = "vertical"
android:background="#drawable/rect"
android:text="Text"
android:textAppearance="?android:attr/textAppearanceMedium" />

I just came across this issue, so maybe someone will make use of this answer:
Define the TextView color attribute explicitly to white and it won't change in touch events.

Related

Android TextView dynamically re-centering

I have a TextView that I want centered in my layout, so I have the following:
<TextView
android:id="#+id/workoutText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="This is dynamic"/>
My problem is that I don't want the centering placement to be re-evaluated every time the text changes. When the text changes to "This is longer dynamic text", the center of the text will be re-evaluated thus pushing the text over to the left on the screen. I only want the center to be evaluated based on my initial static text I put in the layout. Is there a way to do this?
I have succeeded in accomplishing my end goal by placing another TextView below with:
<TextView
android:id="#+id/workoutText2"
android:layout_width="wrap_content"
android:layout_height="0px"
android:layout_centerInParent="true"
android:text="This is longer dynamic text"
android:alpha="0"/>
But this feels a bit hacky and would fail to work if the text dynamically changed to something longer than "This is longer dynamic text".
you should add a gravity proprety to the TextView like this
<TextView
android:id="#+id/workoutText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:gravity="center"
android:text="This is dynamic"/>

Button Margin Changes with Button text content

Let's start with the fun part, here's the graphic of the trouble. Horizontally, everything is beautiful.
The middle button, I'd like to to be aligned with the other three. Here are the basics:
overall, it's a relativelayout
inside this relativelayout, it's a horizontal linear layout, containing the three buttons
the "sinking" of the middle button is 100% correlated with it being a dual line of text, if I change it to a single line, it aligns properly
the specified height of the buttons has nothing to do with the sinking, even at more than double their current size (from current 70 to 170) the exact same behavior (and size of behavior) is displayed
The "custom_button" background has no effect, if I change them all to no background, stock looking buttons, the same positioning occurs
And here's the XML (of just the linearlayout within the relativelayout):
<LinearLayout
android:id="#+id/wideButtons"
android:layout_below="#+id/buttonClockFinish"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:orientation="horizontal">
<Button
android:id="#+id/buttonLog"
android:layout_weight="1"
android:layout_height="70dp"
android:padding="0dp"
android:layout_marginRight="3dp"
android:layout_width="fill_parent"
android:background="#drawable/custom_button"
android:text="View Log" />
<Button
android:id="#+id/buttonLocation"
android:layout_weight="1"
android:layout_height="70dp"
android:padding="0dp"
android:layout_marginLeft="3dp"
android:layout_marginRight="3dp"
android:layout_width="fill_parent"
android:background="#drawable/custom_button"
android:text="Location\nD1-RS" />
<Button
android:id="#+id/buttonHelp"
android:layout_weight="1"
android:layout_height="70dp"
android:padding="0dp"
android:layout_marginLeft="3dp"
android:layout_width="fill_parent"
android:background="#drawable/custom_button"
android:text="Help" />
</LinearLayout>
So why on earth is it not aligning?
I was just about to post this question, and did one final experiment. I added a THIRD line of text to the button. This pushed it down even further. But what I realized it had in common was that the text of the top line of the middle button remained perfectly aligned with the text of the two buttons to either side of it.
So it wasn't that it was having trouble with an interior margin, unable to squish the text against the top border. The alignment was of the TEXT, not the button graphic. All along I had thought that there was some mystery :padding that I was not nulling out, but with three lines of button text it was quite happy to have just about 1dp or so of padding.
The solution was to add
android:layout_gravity="center_vertical"
to that button. I added it to the rest of them too, just for consistency.
Lesson: When you think things aren't aligning, perhaps they actually are, but maybe you're looking at the wrong thing.

How to center a text vertically in a narrow textview in Android?

I have a TextView which has a height of 30px and a textsize of 40px. Since the text is taller than the View, I only want to display the middle part of the text.Like this:
But with android:gravity="center_vertical", I only can display the upper part of the text with some bottom part cut off.
And this is my code:
<TextView
android:layout_width="wrap_content"
android:layout_height="30px"
android:textSize="40px"
android:text="ABCDEFG"
android:gravity="center_vertical"
/>
Anyone knows of any way to do that? Thanks!
Can't you simply wrap it in a LinearView set to the appropriate size and adjust the margin within the textview to about half (depending on padding) the font size?
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="20dp"
android:background="#android:color/white">
<TextView
android:gravity="center"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#android:color/black"
android:text="Sliced in half"
android:textSize="60dp"
android:layout_marginTop="-30dp"/>
</LinearLayout>
Resulting in:
http://i.stack.imgur.com/jEdxx.png
I highly doubt whether you can do that. All the options that I have come across while dealing with TextView are for when the Text is smaller than the View. This is the first question that I have come across which has the requirement otherwise.
One option which I had used before was android:scrollHorizontally="true" where in you specify whether the text is allowed to be wider than the View.
Interesting question. It would be great if you could add some code though.

How to fade edge of TextView in Android?

I am working on Android 3.0.
I have a TextView on my layout and I want it to be faded after 8 characters like in the main menu. This Text is located in RelativeLayout.
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/item_name"
android:textStyle="bold"
android:textColor="#color/white"
android:maxWidth="50dp"
android:maxLength="8"
android:layout_below="#+id/item_frame"
android:layout_alignBottom="#+id/item_view"
android:layout_centerHorizontal="true"
android:fadingEdge="horizontal">
</TextView>
Does anyone has an idea how to fade the text after few characters?
I think you need to combine fadingEdge with ellipsize and singleLine, and even then it will only happen if the text is longer than the control's width.

EditText hint disappears with gravity

I have seen many similar questions to this one but I think this still covers new ground:
1) Hint text disappears when you set gravity
2) android:ellipsize="start" fixes that so you can have centered hints and centered text
3) why does the code below still show centered hint text?
<EditText
android:id="#+id/details"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:hint="use this area to provide specific identification information including approximate size, vessel name and registration numbers if available"
android:background="#android:drawable/editbox_background"
android:layout_below="#id/details_title"
/>
is it because of fill_parent instead of wrap_content? i thought maybe it was because this hint is multiline, but i shortened it and it still appeared and was centered. those are the only differences between this and my other EditTexts that needed android:ellipsize="start" to display correctly. is it just a bug?
You need to use android:gravity="top" instead of center in order to have your hint and your text start at the top left of the box.
add this attribute to your EditText
android:ellipsize="start"
It just works
<EditText
android:id="#+id/details"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:ellipsize="start"
android:hint="use this area to provide........"
android:background="#android:drawable/editbox_background"
android:layout_below="#id/details_title"
/>

Categories

Resources