How to scroll programatically a ScrollView?

I have a little problem with a ScrollView. I have a layout for an activity which is made with a ScrollView. This scrollview contains two ListViews.

<?xml version="1.0" encoding="utf-8"?>

<ScrollView xmlns:android=""
android:id="@+id/rootViewGroup" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:scrollbars="vertical">

<LinearLayout android:orientation="vertical"
    android:gravity="top" android:layout_width="fill_parent"
    android:layout_height="wrap_content" android:background="@drawable/cmb_bg">

    <ListView android:id="@+id/accountsListView"
        android:layout_height="wrap_content" android:scrollbars="none" />

    <ListView android:id="@+id/cardsListView"
        android:layout_height="wrap_content" android:scrollbars="none" />


In the onCreate method of my activity I compute ListViews height according their contents.

During execution, on activity launch, ScrollView is already scrolled a bit.

So I tried, at the end of onCreate to call method scrollTo(0, 0), but it does not change anything.

Any ideas?

Asked by: Lily134 | Posted: 20-01-2022

Answer 1

AHHH!!! Remove ScrollView and leave only ONE ListView in your activity. It's not intended to work this way .If you want to have different content in your ONE listView - modify your adapter, or change the UI But never, ever put different scrollable containers on the same screen/inside each other here is a related post. In theory you can slap two listview on the screen, but expect things to be weird. And i would really redesign it with with either separators or expanders or just with one ListView.

Answered by: Lenny538 | Posted: 21-02-2022

Similar questions

scrollview - Programatically scroll to the last view in android

I want to scroll to the end of the view. Currently i am trying to scroll the scrollview to the end of the latest added view. I tried with setscrolly, smoothscrollto. both works but the problem is both wont scroll to the end, it just scrolls to the last-1 view. Please suggest me how to overcome this.

Android how to move scrollview child to top programatically

I have a ScrollView which contains numerous views on LinearLayout.I have implemented expand and collapse layouts. OnClick of view,it either expand or collapse.So when a view expands,I want to programmatically move ScrollView such that the view comes on top of the screen.See image below

android - how to arrange button at bottom of scrollview programatically

Here is my code to display button at bottom of scroll view programmatically.but only scrollview is displaying.button is not displaying on the to fix this. LinearLayout ll = new LinearLayout(this); LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams( LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT); ll.setLayoutParams(lp); ScrollView scrollView = ne...

Android overlay scrollview by programatically adding a fragment on top

Im making a layout in which i have a "header", and below it a scrollview. Below the header, i want to add another fragment that should be drawn on top (i.e. overlay) the scrollview. I currently have this: &lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;RelativeLayout xmlns:android="" android:layout_width="match_parent" android:layout_height="match_parent"&g...

android - Can i set scrollview below header view programatically?

I have Header which is in relative layout. Can i set scroll view below this headerrelative layout PROGRAMATICALLY?

android - Adding views programatically to a relative layout within a scrollview

Please bear with me as I am new to the use of Views and Layouts. I am trying to create an application in which the user can enter a text field, press a button and have a new text field appear and they can continue adding text fields in this way. My solution was to have the top level be a scrollview and then have a relative view as a child within that(this way I can then programatically insert more editvie...

android - How to change custom component height programatically

I've prepared custom component based on LinearLayout. Whole component is defined in XML. Currently to use it you have to write: &lt; android:layout_width="fill_parent" android:layout_height="44dp" /&gt; Is it possible to set width and height in the java constructor? So it would be possible to write just: &lt;

How to change string resource xml values in Android programatically?

Is there any possibility to Edit String.xml values in Android? Please suggest me the possible ways. I want to provide Enable/Disable option for my App. To accomplish this I can use SQLite database. But I doesn't like to Use DB for a single variable value. Thanks in Advance. With Regards, Raghavendra K.

Android: (Newb Question) Programatically creating views based on xml

Sorry for the Newb-ness. I want to create a list of view elements in a LinearLayout (vertical). I created an xml layout that is a TableLayout called "category_list.xml" &lt;TableLayout&gt; &lt;TableRow&gt; &lt;ImageView /&gt; &lt;TextView /&gt; &lt;CheckBox /&gt; &lt;/TableRow&gt; &lt;/TableLayout&gt; I want to iterate an array, on each itera...

registry - Android: Programatically changing phone settings and getting lost calls

Is it possible in Android to programatically change the phone internet settings (proxies also), email settings and other similar? Is there some kind of registry? and what about getting the lost/received/etc calls? is it possible to get that info?

Programatically send SMS to email using Verizon Motorola Droid on Android

I was wondering if anyone knew the proper way to send an SMS message to an e-mail address using Verizon's CDMA Motorola Droid phone. The internal messaging application appears to automagically do this. While 3rd party applications like SMSPopup don't seem to be able to properly reply to e-mail addresses unless you compose the message inside the messaging application. When the internal messaging applicatio...

java - After making a call programatically, my android app crashes

The title explains all... I have this snippet of code in my application: String url = createTelUrl("3112007315"); Intent intent = new Intent(Intent.ACTION_CALL); intent.setData(Uri.parse(url)); context.startActivity(intent); It does make a call, but once the call ends, my application crashes. I'd like to return to my application once the call has finished, but I read

android - Programatically detect presence of hardware call/hang up keys

One of my clients wants a code method that returns a boolean. True if the Android phone has hardware red/green call/hang up keys and false if it does not. Sonething like this : public void keyFeedbackFromInput(KeyEvent event) { if (event.getAction() == KeyEvent.ACTION_DOWN &amp;&amp; (event.getFlags() &amp; KeyEvent.FLAG_VIRTUAL_HARD_KEY) != 0) { // perform your logic here } }

dtmf - How to Programatically Dial a Phone number in the Android SDK?

How do you programatically do this in the Android SDK: Dial a phone number Bypass the keypad screen Send additional DTMF after the number is dialed Bypass the send DTMF tone prompt I have managed to do 1 till 3 by dialing +555-1212w1234 but I am wondering if anyone knows how to bypass the send DTMF tone prompt.

android - Creating an ImageView with a certain style programatically

I want to do this programatically: &lt;ImageView style="@style/TitleBarSeparator" /&gt; Where TitleBarSeparator is: &lt;style name="TitleBarSeparator"&gt; &lt;item name="android:layout_width"&gt;1px&lt;/item&gt; &lt;item name="android:layout_height"&gt;fill_parent&lt;/item&gt; &lt;item name="android:background"&gt;@color/title_separator&lt;/item&gt;...

android - How to connect to internet programatically?

HI, I'm building an Android application requiring internet connection, and I'm using ConnectivityManager to check whether the device is connected to internet or not. Now, what's the best strategy if it's not connected? Should I quit the application and tell the user to first connect to internet? or is there any way to ask the user if he wants to get connected and connect programatically? Thanks Jul

Still can't find your answer? Check out these communities...

Android Google Support | Android Community | Android Community (Facebook) | Android