I created a user form which fits the window in vertical orientation. When the user slides the keyboard the form doesn't fit the screen (horizontal orientation). I tried to add the scrollbar but it is not visible.
I would appreciate if anyone could show how to modify the following layout file in order to display scrollbar when the orientation is set to horizontal.
Thanks!
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:orientation="vertical"
android:scrollbars="vertical"
android:scrollbarAlwaysDrawVerticalTrack="true">
...
</LinearLayout>
Remove the scrollbar attributes and wrap the whole thing in a ScrollView.
You can't replace the LinearLayout with ScrollView because ScrollView only supports one Direct Child and LinearLayout may have many. So the only option i see is to wrap
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:overScrollMode="always"
android:isScrollContainer="true"
android:scrollbarAlwaysDrawVerticalTrack="true"
android:scrollbarStyle="outsideInset"
android:scrollbars="vertical">
You can pick a variety of other attributes. These worked for my implementation. It is the first container in my layout.LinearLayout is a child of this container. Other UI elements are part of LinearLayout
Hope this helps...
Alex
Related
The title of question might look similar to other questions but It's not. I have several strange problem that I am not being able to solve it.
I have a xml layout and the structure of that layout looks like below.
LinearLayout
|
ScrollView
|
LinearLayout
|
TextView
EditText(multiLine)
The xml:-
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Large Text"/>
<EditText
android:layout_width="match_parent"
android:inputType="textMultiLine"
android:layout_height="match_parent"/>
</LinearLayout>
</ScrollView>
</LinearLayout>
Now let's discuss about problem.
If I keep adding new line to the editText, the editText itself scroll and the TextView which is located above EditText is not scroll. But what I want is EditText not to scroll and leave the job for scrollView so that the textView which is loacated above EditText also scroll along with EditText when new Line is added.
ScrollView behave ok when I press back(usually when the editText is not focused anymore).
Setting to
<ScrollView
...
layout_height="wrap_content">
fix the problem but the desired height then compromised. Same thing happen with Horizontal scrollView also.
Is there any way to solve this problem ? Detailed Answer will be helpful.
Set your EditText's height to wrap_content so it expands instead of scrolling. Set your LinearLayout's height to wrap_content so it's the size of its contents, i.e. the TextView and EditText.
The ScrollView should be whatever height you want for your "window" into the contents layout, the LinearLayout that moves up and down "behind" the ScrollView.
The scrolling happens if that contents layout is too big to display in the visible ScrollView, which is why that contents layout should always be wrap_content (the size of the contents) and never match_parent (the size of the scroll view "window"). If the contents are always the same size as the scroll view, they'll never need to scroll, right?
My Layout has a few complex layouts and they are pretty big. That's why I need a ScrollView. But whatever I try it doesn't work.
Here is my layout file:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="fill_parent"
android:fillViewport="true"
android:layout_weight="1"
android:orientation="vertical"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.33"
android:id="#+id/Linear1"
>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:background="#color/tileColor1"
android:layout_weight="1"
android:id="#+id/tileLayout1"
android:onClick="openFirst"
>
I have only posted a part of it but all the closing tags are ok and inside my RelativeLayout there are 2 textViews and an image. There are 9 more RelativeLayouts with the same structure.
How can I fix the problem and why doesn't it work? It doesn't even show a scrollbar.
EDIT
I have uploaded my full layout to pastebin
EDIT 2
On the developer.android it is said:
You should never use a ScrollView with a ListView, because ListView takes care of its own vertical scrolling. Most importantly, doing this defeats all of the important optimizations in ListView for dealing with large lists, since it effectively forces the ListView to display its entire list of items to fill up the infinite container supplied by ScrollView.
Mine doesn't deal with the scrolling at all. I suppose it is this way because I edit LayoutParams in code. How do I fix this?
1. Try removing android:layout_weight="1" and android:orientation="vertical".
2. Ensure that there is only one ViewGroup inside the ScrollView (i.e. one child as they say). I assume you've done this, but as you haven't provided your full layout I couldn't confirm it.
ScrollView only accepts one child view. So wrap everything inside it in a LinearLayout with wrap_content set as height and you're set.
I had the same problem, and I do not know if my solution helped (mainly because it is a very late response), but my ScrollView not worked since set up a layout that fit exactly on the screen, so it was not necessary to create scrolling. When increased my layout (I put all my items with
android:layout_height = WRAP_CONTENT) became operational.
I tried to search everywhere for what I got stuck on it here, the issue is the scrollViewI have two problems with the scrollView:The first problem;The scrollView not give all of the content that has,I tried to add the following line: android: fillViewport = "true"But it did not helpĀ Second problem;Full content shown leaving the space at the end and ends at the end of scrollView content
enter code here
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true"
android:orientation="vertical"
android:layout_weight="90"
android:padding="15dp"
android:id="#+id/scroll_view"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:orientation="vertical"
>
....
Thanks to those who could help me...
Do you need to set layout_weight in your ScrollView?
If not remove this line or set it's value to 1.
Also change the layout_width & layout_height to fill_parent in the child view.
I first posted this as a comment, but since it solved the problem, I'll post it as an answer instead.
The attribute android:orientation does not apply to ScrollView; you should remove it. Also, you should remove the android:layout_gravity="center_vertical" attribute in the child view; it's not appropriate for the child of a ScrollView.
I am putting more than 15 buttons in one .xml file. But it seem only to be displaying the top 9 of them ? Why aren't the other buttons showed or can't I scroll down to see them?
I am using a LinearLayout with tags.
Are you using a LinearLayout perhaps to contain the buttons? Or any other layout that's not contained in a ScrollView? Good chance your buttons are being drawn, they are just outside your screen.
Wrap your layout in a ScrollView like so:
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true"
android:scrollbars="none" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<!-- your buttons here -->
</LinearLayout>
</ScrollView>
This makes your layout scrollable, so you will be able to just scroll down and see your buttons.
Did you use this?
android:orientation="vertical"
Please post your code,
Are you wrapping everything is ScrollView?:
<ScrollView android:id="#+id/ScrollView01"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
</ScrollView>
More info http://developer.android.com/reference/android/widget/ScrollView.html
when I turn the phone and the screen is rotating I cannot see the whole screen anymore. This is ok but I cannot scroll! Do I have to set some flag or property for scrolling? This is part of my xml...
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:focusable="true"
android:focusableInTouchMode="true"
android:layout_width="fill_parent" android:layout_height="fill_parent" >
<TableLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:stretchColumns="*">
...
</TableLayout>
<TableLayout android:layout_width="fill_parent" android:layout_height="wrap_content"
...
</TableLayout>
</LinearLayout>
Thanks!
You have to put your complete layout inside a ScrollView in order for it to scroll.
It scrolls if your layout height is more than the screen height, which happens generally in landscape mode.
In your case put the LinearLayout inside a ScrollView, since ScrollView can only have 1 child.
You must know that in order to use an scrollView , you must put only one component inside (maybe a linearLayout) .Maybe that's your problem if you are trying to put in more components at that level.