Reputation: 946
First of all i want to apollogize for my english, i am from Russia and i hope that google translater helps me to describe my problem=). So problem is - i have a gridView and ExpandableListView inside ScrollView, i know that i shouldn't put a something scrollable View inside ScrollView, but for my goal i cant find alternative. In my project i have a business catalog with categories(like "Electronics","Home&Garden","Motors" etc), and all i want to do is to put most popular categories into gridView (and add icons to them) and make scrollview to scroll it like single layout. But my scrollView won't scroll it, how i can do that?
my bizCatalog Actvivty:
my bizCatalog layout:
<?xml version="1.0" encoding="utf-8"?>
<ViewSwitcher xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/bizSwitcher"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical" >
<ProgressBar
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Загрузка списка..." />
</LinearLayout>
<ScrollView
android:id="@+id/bizScrollView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<GridView
android:id="@+id/bizFavoritesGrid"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:columnWidth="90dp"
android:gravity="center"
android:horizontalSpacing="10dp"
android:numColumns="auto_fit"
android:paddingTop="10dp"
android:stretchMode="columnWidth"
android:verticalSpacing="10dp" >
</GridView>
<ExpandableListView
android:id="@+id/bizList"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:cacheColorHint="#00000000" >
</ExpandableListView>
</LinearLayout>
</ScrollView>
</ViewSwitcher>
Upvotes: 1
Views: 3713
Reputation: 1325
You can achieve the above by override the dispatchTouchEvent(MotionEvent event)
function for scroll view. inside this function send the events to your child listview. then also you need to override dispatchTouchEvent for your listview like this
int[] location = new int[2];
listView.getLocationOnScreen(location);
if (e.getRawX() > location[0] && e.getRawX()< location[0] + listView.getWidth() &&
e.getRawY() > location[1] && e.getRawY() < location[1] + listView.getHeight())
{
int[] checkListLoc = new int[2];
listView.getLocationOnScreen(checkListLoc);
var offset = checkListLoc[1] - (e.getRawY() - e.GetY());
e.OffsetLocation(0, 0 - offset);
listView.dispatchTouchEvent(e);
return true;
}
return base.dispatchTouchEvent(e);
Upvotes: 1
Reputation: 676
Remove scroll view first. use listview and add gridview as footerview of listview. it will work great. Definitely solve your problem.
Upvotes: 0
Reputation: 7439
As per Android guidelines, you cannot use one scrollable layout into another. If you are using ScrollView then you ca not use ListView inside it. Because both of the layouts are scrollable. So please use any one to scroll your.
Upvotes: 0