Change TextView Text Alignment for Individual Appends - java

I am trying to create an Android app where data is read and alignment differs if a certain string is contained in the data. The data is then appended onto a textview with a carriage return. Using append, is there any way for me to change the text alignment for individual line entries? Currently what I've been doing is this
if(returnedData.contains(myVar)) {
myTextView.setGravity(Gravity.END);
} else {
myTextView.setGravity(Gravity.START);
}
Obviously this does not work because it changes the alignment of every line with each new append. Thank you ahead of time for any help.

android:layout_gravity is used to align the text view with respect to the parent layout. android:gravity is used to align the text inside the text view.
put these lines in your xml
Further make sure that you are trying to align the text inside the textview to the right or do you want to move the text view itself to the right with respect to the parent layout, solution will differ with different scenario.
also you can take two different textview and align that textview rather than setting them on single textview.

Related

Android Horizontal Layout with text wrap functionality

I want to create an layout, in which I should be able to add views dynamically and it should expand horizontally in a flow.
Here are things that I've tried:
Flow-Layouts
Problem with flow-layouts is that when using multiple textviews, if textview having long text, it takes whole textview to next line, but I want it to wrap the text and only move rest of the text to new line.
Spannable Textviews
I want to assign individual id's to views because when it's clicked it should highlight and function accordingly but with spanning it's not possible.

Android: how can I display a string until the string reaches the end of a one-line textbox and display the rest in a different textbox?

I like to think my title question is adequate, but the details are:
I have long strings (sentences in a story) to display and want it displayed in a number of textviews, with only one line in a box. If the string is too long, I want to truncate at a space or punctuation mark, then display the rest in another textview (or views if the string is really long). My display would have many textview, each with one piece of the string.
So, the question: how can I truncate a string at the end of a textview but not before? I do not know how many characters per line.
Second question: how do I capture the remaining piece of sentence and display it in the next textview?
The idea is to have a line of a complete sentence and a translation of the sentence appearing in the line below. If the sentence is longer than a single line, the truncated first part will have a truncated, translated line below it, then the remaining part of the original sentence below that, then the remaining part of the translated sentence below that. So, alternating lines of English text and Spanish text displayed.
For the line breaks, I suggest setting up a TextView that has the width of your on-display TextViews with wrap_content for its height. This will be an internal TextView that is for processing only and not for display. You will need to get the TextView to measure itself. This can get you started. Of course, if the text is already displayed on-screen, you can just use that TextView.
Once the view is measured, you can get its internal layout which most likely is a StaticLayout. (You can also use StaticLayout directly without the TextView.) Since the StaticLayout is a representation of the text display by the view and are the same lines of text that would display in the TextView, you can move them over directly to single-line, on-screen TextViews as long as those TextViews have the same characteristics as your internal one. StaticLayout has methods to retrieve individual lines of text.
There are details that you will have to work through, but that is the gist.
Update: I took the liberty of making a small demo app. This app takes a paragraph of text and splits it into the constituent lines. Those lines are then displayed on-screen with the original paragraph as seen below:

Add value to arraylist from edittext inside recyclerview

I am working on a recylerview which contains several edit text and 2 textview beside each edit text. Initially I want empty edit text when activity is loaded, after that putting some values in 1 or more edit text randomly. I do not want to loose the value on scroll up or down. Please provide a solution for that if possible.

Move to specific position in TextFlow JavaFX

I'm having a TextFlow inside a StackPane which is inside a ScrollPane. I'm adding text with different colors to this TextFlow
Text txt = new Text(msg);
txt.setFill(Paint.valueOf(color));
txtFlow.getChildren().add(txt);
I want to scroll to a some specific point in the textflow.
e.g. First text that is in blue color.
I know I can get the text and check the color. But how can I scroll down to that specific position?
Can I achieve that sort of functionality through the TextFlow?
Simply I'm trying to build up a diff view in JavaFX. And want to travel through the diffs.
I would take a ListView and put some stackpanes or directly the texts in it.
Text content = new Text("Custom Text");
content.setFill(Color.valueOf(yourcolor));
ListView<Text> list = new ListView<Text>();
list.add(content);
Because...
there's a void scrollTo() where you can scroll to the item directly by the Text object or to the item by the index (int).
To get a transparent background on the listview you can use:
list.setStyle("-fx-background-color: transparent;");
I hope this helped you.
I'm sorry if I missunderstood your question.
Peace
Use one of the free styledtext-editors - they all are using ListView or VirtualView internally. See https://github.com/TomasMikula/RichTextFX/wiki/JavaFX-Controls-for-Code-Editing for examples

Android TextView OverLapping

I am trying to create a top bar for my app that shows the users level, coins. So i have an image view that displays the coin icon and a textview that displays the number of coins, if the number gets high it overlaps the image rather than pushing back the image and keeping everything aligned, is there a way to do that?
Without knowing your layout XML this is pure guesswork, but I'm assuming these two views are in a RelativeLayout. If so, add to one of them an attribute like this:
android:layout_toLeftOf="#id/otherViewId"
Options available are layout_toLeftOf layout_toRightOf layout_above and layout_below.
Post your layout XML and I'll update this with a better answer!
If you are using the relative layout then you can use the z-index attribute of views to manage the ordering.

Categories

Resources