So.. I guess the topic might be a little bit confusing. Actually what I want to do here is:
(1) ScrollView x 1
(2) TextViews inside the ScrollView are aligned Horizontally and also vertically
(3) TextViews should be generated by code
The following images might explain what exactly what I want to achieve.
Unfortunately I do not have enough reputation points to post image directly, so posting the link of it is what I can do for now. Sorry for the inconvenience.
The image shows the result I want, is it possible to generate TextView in that way?
I have no idea on generating textviews that are already inside a LinearLayout and the LinearLayout should also be placed inside a ScrollView. It seems complicated. Not sure did I explain it well, hope there is a way to do it.
Thanks FOR Helping!!
Related
I am kind of new to Android Studio and I have been having lots of issues with the designer. I format everything in the drag and drop designer and then as soon as I press play and run the project, all the buttons and edit texts just bunches up in the top left corner. I've searched around online and it looks like I have to learn how to use linear layouts or relative layouts and XML. Can someone explain this to me or maybe point me in the direction of a tutorial?
Seems like the root element for the .XML file is a ConstraintLayout. You should read about LinearLayouts and then RelativeLayout to get started. To explain in simple terms, a LL uses a linear heirarchy to stack views vertically or horizontally amongst each other. A RL is used to position views relative to each other, ie, the position of one view depends on position of another view. ConstraintLayout is the latest and most powerful one, which is used to reduce deep nesting of views by defining certain constraints amongst views in the layout.
Also, for future question posts, please include code snippets which you think are causing the problem. It helps a lot. Cheers!
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.
Good evening,
I am trying to wrap my text around an image view like the question is asking here:
Textview wrap around View
in landscape.
but I wish to not do it in HTML / CSS. plus, that question is 2 years old. I am hoping someone has figured out a work around with this.
Also, I wish to keep my portrait view the way it is with the img view under the text view i.e. no wrapping.
Can anyone help me?
A work around I can think off the top of my head and from previous issues with TextView formatting, the best way is to have, say, a RelativeLayout, and just place 3 separate Views inside of it. It will represent the TextView that is right next to the image, the ImageView itself next to the text, and then the last TextView under the first text, but with the layout_width="match_parent". There is no other way to do this with the TextView or ImageView otherwise.
EDIT:
The only other workaround I believe you can do if you are so intent on using 1 TextView, I would suggest using SpannableStringBuilder with SpannableString. I didn't originally give you that as an option for a specific reason. If you go back to that link you posted on your question, one of the answers say they found an answer. I believe that person linked to a good resource, but they are wrong for what your needs are. When using SpannableStringBuilder, you are essentially creating a string that can have potentially many different version of a single string into one, like 3 different colors on a single string, or strings with 3 different sizes, all in one TextView. Like what you need.
Now the link talks about putting an image and having the text wrap around it nicely, but its not that simple, and that example isn't what you need. What you could do to provide it all in one TextView is to add line breaks after the first few lines where you know the image will be to the right, and then not do so after the image. But the thing is it still needs to go in a RelativeLayout. But instead of two TextViews you only need one. Just place the TextView at the top left of whatever the parent is and the ImageView to the top right of whatever the parent is. This simulates a floating element. But I think doing it that way is more trouble than its worth. It really is because you have to do calculations to figure out where to put the line breaks, etc. You are better off using two TextViews in which to make it look like you need. So in my opinion, DO NOT USE SpannableStringBuilder, but if you do not mind trying to figure out all that spacing, that does give you what you need with a single TextView.
Any easy to make a simple linearlayout with a buncha textviews scrollable? Right now, the last textview gets cut off...
(I don't really wanna use a listview)
Use ScrollView
An example here:
http://www.androidpeople.com/android-scrollview-example/
You can find many more examples using Google.
I have a TableLayout with a tableRow and a horizontal scroll view in the 2nd column, but the right side always gets cut off. IF i have only 1 tableRow, it works, otherwise it goes past the visible area of the screen. To simply and isolate the problem heres an xml file with the guilty culprits. It seems basic but i have been super frustrated trying to get this to work.
. for some reason Stackoverflow isnt displaying my code correctly, heres a pastebin.
link text
To fix this, i found out using
android:shrinkColumns="2"
(2 being the column with the horizontal scroller) fixes the issue.