Skip to content Skip to sidebar Skip to footer

Focus Scrollview On Top Of Page In Android

I am having an Activity in which I am having some View that is textViews ImageViews and MapView and last is listview on the page. All these controlls are in a scroll view. The prob

Solution 1:

Two things you can have a ListView in a ScrollView, you just have to make the ListView a permanent size(without scrolling) when using it.

great example here NonScrollListView

For the ScrollView starting on the ListView, I recommend using android:focusable="false" like you already have in the ListView XML then using

ScrollViewscrollView= (ScrollView) findViewById(R.id.scroll_view);
    scrollView.requestFocus(View.FOCUS_UP);
    scrollView.scrollTo(0,0);

Solution 2:

Vipin is correct in that you can't do a listview inside a scroll view. You could also setup a tablelayout that is made dynamic in Java based off how many items are in your cursor (for loop).

So in other words, setup your XML with a scroll view. Add items to it that will show at the top, then at bottom put your table. Build table in Java with buildRow(). Then call it after you call your setContentView(R.layout.xmllayout);

Solution 3:

you can not use list view inside scroll view you can do two things to get the same

(1)decrease the height of you views so that they can be fit to actual screen and remove scroll view and defaul scroller of views will work.

(2)intead of list view try to create layout having rows as list view

LinearLayout parent = newLinearLayout(this);
parent.setOrientation(VERTICAL);
parent.setLayoutParams(newLayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);//for(numberof rows in your list)
{
LinearLayout row= newLinearLayout(this);
row.setOrientation(Horizontal);
row.setLayoutParams(newLayoutParams(row_width,row_height);

TextView text= newTextView (this);
text.setText("your text");
text.setLayoutParams(newLayoutParams(text_width,text_height);
row.addView(text);
.
.//other view you want to add as check box etc
.
.
parent.AddView(row);
}

this.addView(parent);

hope this will help you

note:but incase you have a large numberof rows it may cause memory issues

Solution 4:

I tried many alternatives but only this worked for me:

ScrollViewscroll= (ScrollView) findViewById(R.id.addresses_scroll);

    scroll.setFocusableInTouchMode(true);
    scroll.setDescendantFocusability(ViewGroup.FOCUS_BEFORE_DESCENDANTS);

Solution 5:

In case you have listview as child in scrollview, scrollview will move its focus to listview. To avoid so i tried many options, but this one worked perfectly for me:

 scroll_main.pageScroll(View.FOCUS_UP);

Post a Comment for "Focus Scrollview On Top Of Page In Android"