Is possible to set TextView to have different widths per line? - android

This is what I get so far, using RelativeLayout and android:layout_toLeftOf and android:layout_toRightOf
[BUTTON1][TEXTVIEW: HERE GOES A TEXT........][BUTTON2]
[...THAT MUST CONTINUE IN THIS LINE]
This is what I need:
[BUTTON1][TEXTVIEW: HERE GOES A TEXT........][BUTTON2]
[..........THAT MUST CONTINUE IN THIS LINE...........]
I know I can do it with multiples textviews, but I don't know how to split the text to fit exactly first and second lines.
So, is possible to set textview to stay "right of" button1 and "left of" button2, but only in "line1"?

Not with TextView that platform provides. You may however write own widget to do layout that way. Peek the source of this widget as starting point http://code.google.com/p/android-flowtextview/

I'm afraid not- in android a View is always rectangular. You can't have a view becoming skinny at the top.

Related

Why is my Android phone layout different then my layout on Android Studio?

The layout of my MainActivity on my phone appears very differently than the layout I see on the code editor. Images are included. I am using a TabbedView. However, the problem still exists on any layout I choose (empty/tabbed).
What can I do to solve this problem?
I am concerned about the text "Hello world" in the middle, not in the top left corner. I follow this tutorial and in the tutorial it is correctly positioned.
It works as expected, because section_label TextView width is wrap_content it changes, depending on what text it displays. And the 2nd TextViews position depends on it, so it changes too. You should be able to verify this by setting various length texts in your layout editor.
For what you want to achieve, RelativeLayout is not the best choice and you may want to use i.e. LinearLayout instead, with its orientation set to vertical and layout_gravity of second TextView set to right
This is happen because you are using the RelativeLayout in the relativelayout we can arrage our views in custom position wise by the help of give the android:id=#+id/some_id like this if you want your second view is shown just below the first view then give them the property android:layout_below="#id/view1" in your second view
Please read all the documentation of RelativeLayout form this link
https://developer.android.com/guide/topics/ui/layout/relative.html

Chat layout like whatsapp

Im trying to build a chat layout like whatsapp. I don't understand how they were able to place 'date' at bottom in rightmost corner of layout.
I saw their code, it uses horizontal LinearLayout in which there is
message and date side by side, but then how does the 'I love' part
of message print above date ?
Another problem is that if I use relativelayout to push date to extreme right using alignparentright = true, it expands the entire layout to match parent, which is obvious but undesirable
Please advice me on this
As sketchy as it seems, I can only see that end result being accomplished with four text views.
Name at the top, two lines for the message, and one for the date.
One message line extends all the way across and above the date, the other is below it and next to the date.
You would need to test the textview length to see how much text you can apply to it before it starts to cut off, and apply the remainder to the second message textview.
Gross.
You can try using a FrameLayout in which there is a LinearLayout at the bottom which contains the name of the sender and the message. Then, add a TextView whose layout_gravity is set to bottom|right
You can use the layout and code below to achieve the desired effect.
Source code gist
What I have used is get the width of the text + the time layout and check if this exceeds the container layout width, and adjust the height of the container accordingly. We have to extend from FrameLayout since this is the one which allows overlapping of two child views.
This is tested to be working on English locale. Suggestions and improvements are always welcome :)
Hope I've helped someone looking for the same solution.
I would recommend using the android:layout_gravity="bottom|right" tag on the date TextView. This will attempt to lay out the View as if the container was "pushing" it to the bottom and right corner.
This may or may not work for all Views. But as #codeMagic said, if you saw their code, then it should be apparent, right?

Left and Right aligned Texts in 1 TextView

There is compound drawable option in TextView to avoid using a parent ViewGroup and an ImageView next to TextView. Which is neat and faster in performance as said by lint. I'm trying to do something similar. A TextView with 2 texts inside, one aligned to left, one aligned to write. Sounds strange but it will only allowed for single line TextView.
And to do that, I can extend TextView and set its gravity to right side. And inside onDraw let the super class draw on right side, and then draw text on left side.
Problem is, I'm not really sure about all this. My question is, will there be a big performance difference ? I dont have any slower device to test. I will be using this TextView inside an item layout of GridView, Item layout already have many views, it would be nice if I could merge some views to one. But again, will there be a performance difference, like noticeable by user ? And if there will be, the approach I will be using by extending the TextView, is there any problem or I should try some other way ?
Thank you
From what I have read I would imagine that you are using a custom adapter for your GridView?
If so, cant you just use TableRow and insert 2 TextViews inside that with each layout weight set to 1. Then you will have 2 columns in one row?
Just an idea.

How to put elements on top of each other in the same xml layout?

How can I have more than one button, or a button and a text view in the same location in one layout but one on top of the other?
I want to have a button that is hidden most of the time, but occasionally will have a non intrusive popup that will prompt something. The rest of the time there will be a text view there that is a different size.
Please take a look at RelativeLayouts.
They use android:layout_below and android:layout_above to position elements below/above other elements.
Use TextView.setVisibility(View.VISIBLE) or TextView.setVisibility(View.GONE) depending on your condition and you may not need to put elements on top of each other in the layout.

Android LinearLayout Alignment Issue

This is currently what I have.
All the boxes are linear layouts. But I want the Star to be right aligned. I have added a TextView with " " just to make a little space but I will be removing this. If I change the TextView to fill_parent it causes the Star to go off to the right of the screen (as expected but I was hoping it would fill up everything inbetween itself and the star)
I can't think how to make the ImageView go to the right. The layout_grvaity is currently right but this hasn't changed anything.
Not very good with design ;)
TIA
Better way is to use a relative layout and then set android:alignParentRight="true", otherwise you can try setting width of your view as fill_parent and then set gravity to "right".
Hope this helps!!
A solution is to set the layout width to wrap content for your TextView and its gravity to 1.0. It will take all the unused space and thus push your star on the right without making it go off.

Categories

Resources