Here is my layout :
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<ScrollView
android:id="#+id/button_scroll"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:fillViewport="true">
<LinearLayout
android:id="#+id/buttons"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"/>
</ScrollView>
</LinearLayout>
In my code, I am adding buttons into the horizontal LinearLayout id/buttons. Everything goes well except that after I add enough of them, it never scrolls.
I tried :
call invalidate on the ScrollView
Change the layout_width for the LinearLayout to wrap_content
Try using HorizontalScrollView! ScrollView layout only scrolls vertically, as i found out a few weeks ago trying the same thing!
Related
I have a TableLayout which is populated dynamically with many rows of data. It contains more data than the screen can hold, so I require it to be scrollable.
My issue is that when I place the TableLayout inside of a ScrollView, it appears to cut off many rows from the top of the TableLayout.
For reference, the full code is here (the question is to cluttered already to fit it all) http://pastebin.com/w7Fi3Bzz
See below for the code related to the issue I'm having
Here is the XML without the ScrollView:
<TableLayout
android:orientation="vertical"
android:fillViewport="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center_horizontal"
android:id="#+id/tbl_statistics"
android:stretchColumns="*"
android:paddingTop="20dp"
android:paddingBottom="20dp"
android:paddingLeft="20dp"
android:paddingRight="20dp"
>
</TableLayout>
And what it looks like:
And here is the same XML with an enclosing ScrollView:
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true"
>
<TableLayout
android:orientation="vertical"
android:fillViewport="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center_horizontal"
android:id="#+id/tbl_statistics"
android:stretchColumns="*"
android:paddingTop="20dp"
android:paddingBottom="20dp"
android:paddingLeft="20dp"
android:paddingRight="20dp"
>
</TableLayout>
</ScrollView>
And here is what the table looks like, you can see the top of the table was truncated (it is populated with the same exact data):
I found a similar issue here LinearLayout not expanding inside a ScrollView, but the answers did not help me.
In your current layout:
Remove android:layout_gravity="center" from the TableLayout element.
Add android:layout_weight="1" to the ScrollView element.
Clean and rebuild your project.
Additionally, the fillViewport attribute only works on ScrollViews.
I resolved the same issue only by inserting TableLayout into LinearLayout which is only child of ScrollView. I tried all other variants without success (fillViewport for ScrollView, android:layout_weight="1" for TableLayout).
I used TableLayout to dynamically insert Views to it
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TableLayout
android:id="#+id/activity_displayFields_tableLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp" />
</LinearLayout>
</ScrollView>
I have a parent horizontalScrollview that contains various layouts. In one particular layout there is a scrollview. Inside that scrollview there is edittext.
Now when I click on any edittext for input, the horizontal scrollview automatically scrolls the screen to some other layout and I am not able to see the current active layout(containing scrollview).
I know nested scrollviews is a bad coding practice but I can not change it in this case as there will be large amount of rework. Is there any workaround for this.
Following is the xml code for main layout containing horizontalscrollview:-
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<HorizontalScrollView
android:id="#+id/CloudHScrollView"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
and following is the code for one of the child layouts that is inserted later at some stage. This layout contains the scrollview which has edittexts:-
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ScrollView
android:id="#+id/scrollview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="0dp"
android:background="#drawable/blueoverlay"
android:fillViewport="true" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingBottom="300dp"
android:paddingTop="90dp" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<EditText
android:id="#+id/edittext"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#null"
android:gravity="right"
android:singleLine="true"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#android:color/black" />
</LinearLayout>
</LinearLayout>
</ScrollView>
I'm not sure if this will work, but you can try extending outer ScrollView class and handle its onScroll events on your own.
look here:
listening to scroll events horizontalscrollview android
Android: how to listen for scrolling events?
I had the same issue, solved it by adding the following to AndroidManifest.xml file for the corresponding activity.
android:windowSoftInputMode="adjustResize"
I want to make a ScrollView which includes a LinearLayout:
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:background="#000000" >
<LinearLayout
android:id="#+id/mainHolder"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#000000"
android:orientation="horizontal" />
</ScrollView>
Now when i add children to mainHolder I cant scroll. whats wrong?
ScrollView only supports vertical scrolling. For horizontal scrolling, use HorizontalScrollView.
Adding a horizontal linear layout in a vertical scroll view is suspicious.
For horizontal, scrolling, use a HorizontalScrollView.
Also, wrap_content size in the scrolling direction is meaningless. If it really wrapped to content size, there would be no need to scroll.
try this one
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:background="#000000" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/mainHolder"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#000000"
android:orientation="horizontal" />
</LinearLayout>
</ScrollView>
you are adding the child to the linear layout which is horizontal in orientation
so it wrap the content horizontally
change the orientation of the linear layout to vertical or try Horizontal Scrollview
<LinearLayout
android:id="#+id/mainHolder"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#000000"
android:orientation="vertical" />
i am beginner in android development and i am trying to create a horizontal scroll view that will contain different layouts.
the error that i am facing is : horozontal scroll view can only host one direct child.
please advise thanks in advance
<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tool"
android:id="#+id/horizontalScrollView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:fillViewport="true" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:background="#ff0000">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:background="#ff0000">
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:background="#00ff00">
</LinearLayout>
</LinearLayout>
</HorizontalScrollView>
Not only Horizontal but any vertical scrollview also will give this error.
The error means that there should be only one child to a scrollview and that child can contain any number of sub childs.
So the bottom line is thios you should make only one direct child to scrollview and make your layout in that child only as
<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tool"
android:id="#+id/horizontalScrollView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:fillViewport="true" >
<LinearLayout
android:id="#+id/directchild"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:background="#ff0000">
</LinearLayout>
</HorizontalScrollView>
Now create your desired layout within directchild layout.You will not get any error then
Hi this error is because scrollview can host only on direcxt child .
take a relative or linear layout and write all the layouts inside that
I have a linearlayout A containing a imageview and scrollview. The scrollview contains a second linearlayout B
The idea is to have a fixed header while the linearLayout B contains multiple views that match exactly the height of the scrollview. See it as a tabview where all tabs are after each other in a scrollview.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:id="#+id/main_view"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#000000"
android:orientation="vertical">
<ImageView android:id="#+id/logoImg"
android:layout_width="fill_parent"
android:gravity="center"
android:src="#drawable/logo"
android:layout_height="wrap_content"/>
<ScrollView
android:id="#+id/scrollView"
android:layout_weight="1"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout android:id="#+id/scrollLinear"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
</ScrollView>
</LinearLayout>
I tried to achieve this by calling getHeight on the scrollView and then set this height to each view in the linearLayout B but getHeight always returns 0.
Anyone an idea what's the easiest way to achieve this?
Well, the question is very old, but I'll give it a try :)
Wouldn't it be lack of "fillViewport" in ScrollView?
<ScrollView
android:id="#+id/scrollView"
android:layout_weight="1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true"
>