I am using a FlexboxLayout to add few EditTexts. Each EditText contains just 1 character of words.I am using editText for space as well but keeping it invisible.I am using layout setting FlexWrap as "wrap". For instance, if I have two words, some letters of the second word goes to the next line. However, I want the next word( a group of editText) to go to next line instead of just the last few letters(editText).
Is there someway to group these edittext and make the whole word go to next line.Or is there some way to break line within the programme itself.
I tried adding 'EditText' to linear layout and adding it to 'FlexboxLayout', it did not work.
Use this property to start a new line in FlexboxLayout.
app:layout_wrapBefore="true"
In your case, just apply this property to the EditText which you want start a new line.
Quote from FlexboxLayout docs:
layout_wrapBefore (boolean)
This attribute forces a flex line wrapping, the default value is
false. i.e. if this is set to true for a flex item, the item will
become the first item of a flex line. (A wrapping happens regardless
of the flex items being processed in the previous flex line) This
attribute is ignored if the flex_wrap attribute is set to nowrap. The
equivalent attribute isn't defined in the original CSS Flexible Box
Module specification, but having this attribute is useful for Android
developers. For example, to flatten the layouts when building a
grid-like layout or for a situation where developers want to put a new
flex line to make a semantic difference from the previous one, etc.
Related
Let's say I want to add the word 'supercalifragilisticexpialidocious' to a TextView. How can I specify at what points Android may break up the word when it wraps it across multiple lines?
As an example, I only want Android to break the word at the locations specified by a hyphen as follows:
su-per-cal-i-frag-il-is-tic-ex-pi-al-i-do-cious
In this case, Android might display the word as:
supercalifrag-
ilisticexpial-
idocious
Extend TextView and implement this behavior - there is no in-build approach for that.
Soft Hyphen to the rescue! https://en.wikipedia.org/wiki/Soft_hyphen
First, you must set this property on a TextView:
android:hyphenationFrequency="normal"
Then you use the Soft Hypen character inside your strings:
Like so:
supercalifragilisticexpialidocious
I need to create a custom Span that renders its content like source code. Here's an example of what I am trying to achieve. Let's say we have the following text, where I have annotated the start and end of the custom span using square brackets:
Some text [some\nmulti line\ntext] some more text
The prefix ("Some text") and suffix ("some more text") should be rendered normally, but the custom span should be rendered like a code block:
some
multi line
text
I have been looking at using ReplacementSpan for this, since i Have previously used that to create various interesting custom spans, but for this case I just can't get it to do what I want.
I somehow need to get my span to render a full block of graphics, occupying the entire width of the container. Is it even possible to do this?
Android processes multiline spans line-by-line.
The only way I've found is to override TextView.onDraw, compose blocks for each block-span and draw them before (of after, if you want) TextView.onDraw.
Here is an example activity
https://github.com/Babay88/AndroidCodeSamplesB/blob/master/blockquotespanexample/src/main/java/ru/babay/blockquotespanexample/MainActivity.java
It uses customized TextView
https://github.com/Babay88/AndroidCodeSamplesB/blob/master/blockquotespan/src/main/java/ru/babay/blockquotespan/TextViewWithBlockBackgrounds.java
And special BlockQuoteSpan.
You should ensure that each block span starts and ends with a \n.
Is there any shortcut for editing properties of a widget in Android Layout editor in ADT?
I need to change gravity of TextView lots of times, but every time I have to use mouse...
You could do a search and replace on a particular string in the layout.
Highlight only the TextViews you want the search to happen in
Search > Search
Enter the string to be replaced and press the "Replace" button or "Replace
All" button.
If you post the exact xml listing of your layout, I can be more exact in which string needs to be replaced. If that solution doesn't work for your particular case, to save some time, I suppose you might also be able to create a particular custom Eclipse template for your TextView.
A third option would be to use inheritance and create a customTextView with the gravity already set a certain way.
And a fourth option still would be to set the properties of your TextViews programmatically after the fact using both XML and Java (instead of only using XML).
I have a following issue with laying out text on Android. I'm basically trying to have two lines of text with minimal spacing and each should be styled differently. I've had quite good working solution with two singlelined TextViews one placed below the other, but I've been still getting a little bit cropped text on certain devices..
So I decided to switch to just one TextView an use Spannables instead which should be generally a better solution in all circumstances.
That means I needed to remove the single line property from my TextView -> in order to be able to wrap the line before starting the second Spannable..But there is an issue when is the text displayed at the first line actually longer than it..TextView wraps Automaticaly which is an unwanted behavior. Below you can see several screenshots, which should you better tell what I'm trying to achieve and where I'm now.
The first image shows new layout with spannables and you can see there the wrapped line as well.
The second image is the initial version of the layout woth two textviews layed out verically in a LinearLayout.
There is also a problem it's actually an appwidget, that means I do not have an access to that textview instance directly. I have been thinking about ditching textviews at all and instead use just ImageView and render all manually on canvas..That seems like an overkill to me, so I'm looking for a better solution. Unfortunately I'm kind of out of ideas and knowledge:)
Thank you
If you want to prevent a multi-word string from wrapping, you can replace the spaces with non-breaking spaces ('\u00A0'). TextView treats these as word characters, but renders them as spaces.
I have an android application in which a user can create what is basically a macro and label that macro with some text. I then create a button for them with their descriptive text. The button is a custom view extending Button. In the constructor I set the layout as follows:
this.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
These buttons are then placed within a GridView. Functionally, it's working as intended but I'm running into a layout issue.
If the text is too long, it will break and wrap to the next line, thus increasing the height of the button while maintaining a constant width. The problem is in how the text wraps, it will break in the middle of a word, instead of gracefully wrapping at whitespace. For instance the test "Perform an Action" will render as
Perform an Ac
tion
Ideally, I'd like to wrap gracefully at whitespace instead of breaking words across lines. I suppose I could do this by checking the length of the text and the font against the width of the button and then doing some fancy insertion of newlines myself, but that gives me traumatic flashbacks to making win32 UIs. Is there a better way?
you can add this attribute to your Button's XML that will magically put the whole text in one line:
android:singleLine="true"
or you can verify the text before you insert it to the button and check the number of words.. if it is too long like more than 25 characters then break it on the second or third whitespace then set it to the button.
hope I got your question right.
AFAIK there's no simple way to do precisely what you want. You can get a decent look using android:singleLine="true" and android:ellipsize="marquee". Also, since you have already implemented your own Button class, take a peek at this question
I had a button which said "Off" and had a drawable to the left, but it was wrapping to two lines. i.e.
Image O
ff
The solution was that I removed the drawablePadding style. i.e.
<item name="android:drawablePadding">5dp</item>