how to add scrollview dynamically in android - android

I have android code the display a list of users information , and sometime it needs to have a scroll bar to display all users ?? and sometimes not.. how can i set scrolllayout dynamically not in xml layout file ??

I know your question is on how to do this dynamically, but in your case you should just encapsulate the view in a ScrollView in XML. If the content isn't large enough to require scrolling, it won't scroll.

What is wrong with wrapping xml layout in a scroll view? If you wrap it in the scrollview the scroll will be there when you need it, is it causing problems when you dont need it?

You should wrap it with a scrollview anyways. It won't show the scrollbars unless it needs them.

Related

Android layout then scroll programmatically not working

In my android app, I first programmatically layout a bunch of textViews, in a layout view, then I immediately programmaticallly scroll to a specific textView. Scrolling is not working. I suspect it is because Android has not finished computing the location of things. Scrolling works if I wait between layout and scrolling. I spent the whole day finding a solution. Please help. Thanks.
Default textview can't scroll.
If you want scroolable textview you should use scrollview then add in scrollView,TextView.
Don't add in layout textView. You must add ScrollView.

Scrollview inside of a scrollview

BEFORE YOU SAY "Google says not to do this" PLEASE READ ALL OF MY QUESTION!!
The layout:
ScrollView -> RelativeLayout -> ScrollView -> RelativeLayout
The first ScrollView is necessary because form entries pull up the soft keyboard on some phones which hides the rest of the content. Having a ScrollView as the outer most container allows a user to scroll with the soft keyboard present.
The second ScrollView lower on the hierarchy is a ListView which is still scrollable.
I completely understand why devs are discouraged to have a ScrollView within another ScrollView. I need to figure out a way to get the two to work together. I tried disabling the outermost ScrollView when the inner most ScrollView get's a touch, but that didn't help.
Is there a way to get around this to where both will work (not at the same time of course)? I wouldn't even mind disabling the outermost ScrollView until the content page is changed again. There has to be a way..
Step #1: Remove the ScrollView.
Step #2: Make the first RelativeLayout be a header in your ListView via addHeaderView().
Step #3: Make the second RelativeLayout be a footer in your ListView via addFooterView().
The net effect is that the whole thing will be scrollable, without nested scrollable items.
It will only work when you set the android:layout_height to a fixed value for your second ScrollView. The best way is to set a size depending on device, for that it would be better to create layout for each supported screen size ( value on dp like 150 dp).
you shoud create separate layout: layout-small, layout-normal, layout-large ....
see this link for optimization of the fixed size: http://developer.android.com/guide/practices/screens_support.html
The answer is to programmatically intercept the touch events form the outer most scrollview. I am using a class that I found in another SOF about Disabling a ScrollView Programattically.

Scrollview inside listview issue in android

I am adding a listview inside a scrollview in xml that xml(Screen) is loading from the middle screen. In my design I have a top part like a textview and a list view and middle part like editext and bottom part like button. Page is loading from the middle part. If it scrolls I can only see the above part. I want to load the page from above part. Can anybody tell me what the problem is and how to resolve it?
Thanks
Use android:fillViewport="true" as an attribute in your scrollview tag and it will fill up the screen.
Actually there is no need to use ScrollView with ListView. Use ListView only, you will be able to scroll the items in a ListView.
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.
found it here
using smoothScrollTO(0,0) to fix the issue

How to implement scrolling in TableLayout?

I have implemented simple database android application.In which I have displayed list of name and images.But if data is more then ten then table layout is not scrolling vertically.
Is it possible to implement vertical scrolling without using scrollview?
If possible then please provide me some reference.
Thanks in advance.
Why do you want to do it without using ScrollView? You can simply wrap your TableLayout inside a ScrollView to add the functionality.
I've always used ScrollView so I can't really give you a way to do this without using it.
Random link off Google that explains it pretty well: http://huuah.com/using-tablelayout-on-android/
As #Klaus said, you have to implement a ScrollView. Nonetheless, you can set
android:scrollbars="#null"
in the XML resource and in that way the scrollbar will be "invisible"
Hi
Here is a good article http://blog.sptechnolab.com/2011/02/01/android/android-custom-listview-items-and-adapters/. It is in LinearLayout but is someone write comment over there then i can convert the layout file into TableLayout.

Is there a way to show the scrollbar of ListView all the time?

Is there a way to always show the vertical scroll bar of the ListView?
Sure, it is possible. Try View.setScrollbarFadingEnabled.
There is actually a very easy way to do this using following property in xml file.
android:fadeScrollbars="false"
This will solve the problem.
Simple, make the client area (the area where you are placing the widgets in ScrollView) larger than the screen size. So scroll bar(s) will be visible all the time.

Categories

Resources