Scrolling in android LinearLayout using XML - android

I have made a very simple collection of ImageButtons using XML in android, with the parent layout being LinearLayout with orientation set to vertical.
I read on that LinearLayout adds the scroll automatically if the height of the content exceeds the screen.
The link is: http://developer.android.com/guide/topics/ui/declaring-layout.html
The introduction below the LinearLayout diagram says so.
But the problem is that content is not being displayed after the window's height and content is missing.
I am at my wit's end and have searched other's answered questions... I donot want to use a ListView, but if i have to, i'll do it.
Thanks

Related

Android Horizontal oriented LinearLayout - how to know how many TextViews will fit?

My Idea is adding TextViews with rounded corners background to a horizontal LinearLayout, so if next one wouldn't fit - I will add TextView to another LinearLayout below.
Is there a way to do so? I know it sound like a custom view, but I would like not to bother as much - to adjust height, make click area calculations istead of simple clickListeners
Sounds like a recyclerview using a flexbox layout https://github.com/google/flexbox-layout with flexWrap turned on.
You could also use is in a static layout as well.
With flexWrap it does all the calculations to see if the "item" can fit on a line and if not starts a new line.
Many examples on the github page.
You could keep adding text views in linear layout while checking if newly added text view is outside of linear layout horizontal boundaries, if it is you could remove it from linear layout and add it in new one but I see no reason why you would want to do that.

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

Scrollability of Android Linear Layout

According to this
A layout that organizes its children into a single horizontal or vertical row. It creates a scrollbar if the length of the window exceeds the length of the screen.
I have a Linear Layout (vertical) that consist of a stack of TextView, EditText and one button. Reading the documentation above, I would expect that my layout will scroll by default when there is not enough space to display (e.g. when soft keyboard is on). But apparently it doesn't scroll until I wrap my Linear Layout with ScrollView.
Do I understand the documentation incorrectly? Please help me to understand this. Thanks.
Do I understand the documentation incorrectly?
It is a bug in the documentation. LinearLayout does not scroll on its own.

Layout for chat app in Android

I'm making a chat for Android and I need to make a main xml layout.
There is going to be a TextView to display history, EditText and Send Button. All view should be positioned like in whatsapp. EditText and Button at the bottom of a screen. The rest of the space goes to the TextView.
So how is it possible to do it, so it would look nice at any screen and any orientation?
I tried to do it with android:layout_weight, but I don't think it's going to be very portable.
Thanks in advance.
I don't think a single TextView is the best way to achieve this.
I'd recommend using a ListView instead of a giant TextView to hold the entire conversation history. Each element in the ListView would hold a single TextView and any other required views to display each message in the history, and it will by default allow for scrolling up and down to view the entire history. You can then just adjust the text size to handle different screen sizes.
This is how the default Android Messaging app is implemented, but you can customize each item in the ListView to make it look how you want (like WhatsApp, for example).
Hope this helps.
because layout_weight sets the proportions, but the height of my editText/Button is fixed
So? Don't put android:layout_weight on the fixed portion.
So for different screen sizes, diffrerent height would be given to them, leaving some space.
Then don't put android:layout_weight on the fixed portion. You are hitting yourself on the head with a hammer, then complaining that your head hurts.
Step #1: Vertical LinearLayout.
Step #2: Transcript TextView inside the LinearLayout, with a height of 0 and a weight of 1.
Step #3: EditText and Button (in a horizontal LinearLayout?), inside the vertical LinearLayout, with a height of wrap_content and no weight specified (defaults to 0).
Your fixed-height stuff, with a height of wrap_content, will get its allocation of pixels, and your transcript TextView will get all remaining pixels, courtesy of its weight of 1.
I also echo physphil's suggestion to use a ListView in transcript mode for your chat transcript, rather than the TextView.

how to order the elements in relative layout

friend's
I have a task to place the horizontal scroll or swipe menu tabs in my application i did it where the appears top of the header,but my problem is to place the scroll menu has below the header
i have RelativeLayout where it contains two elements one after another,
TextView - for header
Gallery - for Scroll menu items
from the above code Gallery content been set from my activity,
for example the output i'm getting
looks, scroll menus(Gallery) - Header
(text view defined the above layout)
========================================
but i need it has
Header (text view defined the above layout) -
scroll menus(Gallery)
how can i get it.
thanks in advance.
If you had read at least one time the documentation (the same way for what Maragues said, please mark question as answered when they are otherwise people will not answer you anymore) you should have seen that there are xml attributes to RelativeLayouts like android:layout_below ...
Check this link
Is there something about LinearLayout that makes it unsuitable?

Categories

Resources