I have a xml(registerpage.xml) file and I declared that in a ScrollView so that its scrolling smoothly up and down and I deleted the parent view of this XML.
When I did like this:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/regsrollview"
android:layout_width="fill_parent"
android:fillViewport="true"
android:layout_height="fill_parent">
<include android:id="#+id/registrationlayout"
layout="#layout/registerpage"/>
</ScrollView>
the above code I have written in main.xml and deleted the parentview of registerpage.xml. now the problem is registerpage.xml is not scrolling as before and the softkeypad is disturbing. Now I want to give the controls to the registerpage.xml in activity so that it will scroll up and down(wit some velocity)
How to do this?
Thanks in advance...!
Related
See bottom of this entry for an answer to this "problem".
In my app I inflate some xml views and add them to a LinearLayout, list, within a ScrollView. The XML looks like this:
<ScrollView
android:layout_width="0dp"
android:layout_weight="19"
android:layout_height="wrap_content"
android:fillViewport="true">
<LinearLayout
android:id="#+id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
</LinearLayout>
</ScrollView>
I then try to give focus to one of the views I've put into 'list'. This is done by using this code :
view.getParent().requestChildFocus(view, view);
If the above code results in a scroll down, the focused view get placed at the bottom of the screen and if it result in a scroll up, the focused view get placed at the top of the screen.
Is there a way to make the focused view always get placed at the top of the screen if the length of the list permits it?
Edit: This works! See accepted answer.
XML
<ScrollView
android:id="#+id/scroll_list"
android:layout_width="0dp"
android:layout_weight="19"
android:layout_height="wrap_content"
android:fillViewport="true">
<LinearLayout
android:id="#+id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
</LinearLayout>
</ScrollView>
Sample code to put somewhere in your activity or fragment
view = findViewById(get_view_that_should_have_focus);
ScrollView scrollView = findViewById(R.id.scroll_list);
scrollView.smoothScrollTo(0, view.getTop());
You can vertical scroll to specific view by using this:
scrollView.smoothScrollTo(0,view.getTop());
It will make your view top of the scrollview(if there is enough height) After scrolling, you can request focus for this view.
Since I can't comment, I'm just gonna post this here.
The solution provided by Oğuzhan Döngül is correct, but if some of you can't get it running, try to do the smoothScroll inside runnable :
val topOffset = view.height
scrollView.post {
scrollView.smoothScrollTo(0, view.top - topOffset)
}
I add topOffset to give some spaces on top of the highlighted view.
source
I have a data set and I need to show them using ListView and TableLayout in same xml file.As both ListView and TableLayout are much longer,I decide to use scrollView. I knew that android scrollview can only have one child. So I Coded as follows.
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="8">
<LinearLayout
android:id="#+id/showClaim_layout2"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_alignParentBottom="true"
android:orientation="vertical">
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/claimList"
android:layout_margin="5dp">
</ListView>
<TableLayout
android:id="#+id/showClaimTable"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFEBCD"
android:layout_margin="5dp"
android:shrinkColumns="0">
</TableLayout>
</LinearLayout>
</ScrollView>
When I run the program it's ok. I mean page is scrolling. But it doesn't work as I expected!I need to show all the list element and after end of the list, tableLayout must be show.If the screen size is not enough then we can scroll the page and see the data.
In here ListView does not show all elements of the List and TableLayout show all tableRaws inside ScrollView.
Can anyone tell me that where I got wrong or any other way to do my task easily.
Thanks.
As far as I know, you should never put a ListViewinside a ScrollView, since they implement their own scrolling behavior. Consider changing your design.
"I knew that android scrollview can only have one child." Correct but you forget that that one child should have a height of wrap_content.
Also #haint is correct ListView has its own Scrolling Behavior. Still try android:layout_height="wrap_content" for your LinearLayout
I think you can fix it by using the
layout_weight
set layout_weight for your ListView to 1 and for TableLayour set it to 0;
Be sure after changing set layot*:height to 0dp;
You can check below articles.
first-
second-
xml file for my About Screen .. i've done this because my app supports API 9 which does not support DialogFragments, so i am using another class to display another screen instead .. the problem is, i cant seem to scroll through the whole page, my .xml contains nested LinearLayout that also has TextViews .. i tried adding android:scrollbars="vertical" to the main <LinearLayout> but nothing happens .. i hope someone can help me out, thanks :)
My XML file Pasted here.
ScrollView can only support a single child. So enclose your nested LinearLayouts inside a single LinearLayout and further enclose that parent LinearLayout inside a ScrollView. I have done this for you. You can use this http://pastie.org/9528662
Wrap your root LinearLayout with ScrollView
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!--your nested linearlayouts here-->
</LinearLayout>
</ScrollView>
I'm using android:windowSoftInputMode="adjustPan" in my manifest.xml.
It's doing me the job just fine but there is something retarded about it.
when i focus an EditText view that's, say in the bottom half of the screen, the title bar is also scrolled with the content of the activity.
image here
all i want is to freeze/float the title bar in place when scrolling the content. just like this:
image here
and no, I don't want to use adjustResize It overlaps views on top of each other
any help is greatly appreciated, been looking for the answer for a long time.
Found it!
Simply changing the root view in the layout xml file to a ScrollView does the job.
I don't even need to specify android:windowSoftInputMode
Of course I have to have everything else in a single layout as the child of the ScrollView
Edit
your .xml file should look like this:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
... >
<LinearLayout> // could be any other layout but linear works well here
//insert all other views of the activity here
</LinearLayout>
</ScrollView>
The answer suggested by Ace is essentially what is needed. My answer just aims to make things a little clearer.
There are two things you need to do. Firstly in the Manifest set the following on the activity. android:windowSoftInputMode="adjustResize"
Then, in the activity's layout you'll want to set a ScrollView beneath the Toolbar/Title Bar, as shown in the code below.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_height="?attr/actionBarSize"
.../>
<ScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
...>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
...>
</RelativeLayout>
</ScrollView>
</RelativeLayout>
From what I understand, here's how it works.
When you open the soft keyboard on your device, it will 'adjustResize' the layout of the activity. As the layout sits in a ScrollView, this is the part which is resized, and made smaller. Therefore the Toolbar/Titlebar will stay in place and the layout in the ScrollView will be scrollable when the keyboard is shown.
I have a registration form in a LinearLayout as shown below:
When emulator screen is in it's default position it is working fine. But when I rotate the emulator screen it only displays the elements which are fit to screen and remaining are wrap up. As shown in below screen:
Now I want to make this layout scrollable but not getting the idea. Any help will be highly appreciated.
Try putting your LinearLayout inside an ScrollView like this:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent">
<LinearLayout android:id="#+id/menu_ll"
android:layout_width="fill_parent" android:layout_height="fill_parent"></LinearLayout>
</ScrollView>
I simply added this code in my activity of AndroidManifest.xml
android:windowSoftInputMode="stateVisible|adjustResize"