Android Studio - Kotlin - how to display scrollable text - android

I am new to Android Studio and Kotlin.
I am outputting texts regularly to the display.
Think of an old-fashioned ticker-tape newsfeed, where the latest text is always at the top...
I want to update some field (e.g. TextView) on the display.
However, I want:
(a) the latest text to appear at the top, and
(b) as the number of texts will increase over time, I want the user to be able to scroll down to old texts if they want.
I thought a Scroll View would work for this but I haven't been able to get anything to work as described above.
Can anyone suggest a solution?
Thanks
Garrett

When a control such as a TextView contains more text than the visible one, you can make the view scrollable simply by setting the following two properties for it in the xml file relating to the layout
android:maxLines = "AN_INTEGER"
android:scrollbars = "vertical"
Subsequently, inside the code, just call the setMovementMethod method of the view
yourTextView.setMovementMethod(new ScrollingMovementMethod())

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

how to add search result on top of other views

I have an EditText in my layout which is used to get the search query from the user. I want to show a LinearLayout bellow it when user enters some characters and fill it with the results (This layout should appear after entering at least N characters). But I don't know how to show this layout?
I thought of putting the whole layout shown in the activity inside a FrameLayout and add the view when required, but there will be two problems:
The view will be added on the top left of the screen.
If I want to move it with adding some padding to it, all the area will correspond to the click event.
To explain what I want more, please take a look at this:
I hope this link will help you, you need to use AutoCompleteTextVIew
http://www.javatpoint.com/android-autocompletetextview-example
https://www.codeofaninja.com/2013/12/android-autocompletetextview-custom-arrayadapter-sqlite.html
These is two approaches for your case.
Use AutoCompleteTextView
Use android-popupwindow.
The former is easier and more acceptable, however if your want to customize the layout of the resulting search, for example arranging them in a gird view, you may what to use the latter option.
Although, AutoCompleteTextView internally uses the latter option.

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?

Using Layout - Android

I have a layout, but I need put more views (Buttons, EditText, etc), but how you know, the layout of the ADT is a bit small and I can't to set more views or know where is it, Somebody know How can I set more of these?
Thank you
Android isn't like iOS how you can just position elements with drag & drop.
RelativeLayout will position elements relative to each other and LinearLayout will lay out elements sequentially in a linear fashion, either vertically or horizontally. Both methods are better executed by actually writing the View XML yourself.
I suggest reading this: http://developer.android.com/guide/topics/ui/declaring-layout.html
If you want to actually see what you are adding to your layout without messing with the XML you could maybe change the device that the renderer is using to preview your layout.
I don't know what IDE you're using but in Eclipse and Android Studio you can change the device that your layout preview is rendered on. That way you can see what you're adding as you add it.
Then just make sure to put everything in a scroll view so users can access all the views and widgets you've put in that layout for your activity or fragment or dialog or whatever else it is.

Which layout can provide free drag and drop insertion?

I'm using Eclipse graphical layout, and i want to Drag and Drop components to the layout and i want them to stay at the exact position that i dragged them.
Relative Layout is the closet thing but it changes the location of the components after couple insertion.
thanks.
Rami.
i want them to stay at the exact position that i dragged them.
No, you don't. Android devices come with screens in many different sized and resolutions, so fixed positioning of components is a recipe for making the application unusable to users with a different screen that you.
The point of layouts is that they can adjust to different screen sizes. Learn to use them properly.
You're looking for AbsoluteLayout, but it is deprecated.
RelativeLayout is the way to go, just pay some attention to the hints drawed on-screen when you place your elements.
You should be careful also to avoid circular references otherwise your items will be scattered randomly over the layout. (Example: Textview A on right of TextView B; TextView B on left of TextView A)
Be careful also when you change your element's id because the IDE does not update automatically all the references and thus your layout gets scattered again. When you update an ID you must update all its references in the XML file by hand.
Actually absolute layout is the answer what u want ,but that is deprecated.Relative layout does what you want.But it arrange its child based on parent position.If you drag a text view ,then other view will depend on this text view.If you have inserted 2 view,then third view will depend on the parent(2 views).But in between if u disturb any of the view ,it may affect other views.So do things systematically
In Java what we can typically use is GroupLayout. You may see what the equivalent is for android.

Categories

Resources