Tuesday, 15 June 2010

android - ScrollView is not applied to whole layout -



android - ScrollView is not applied to whole layout -

i want add together linearlayout scrollview children of linearlayout bunch of gridlayouts containing 4 columns. items in gridlayout dynamically populated code. gridlayout can have either 2 or 1 rows depending upon number of content set in mainrows class.

now, since there can many sets of gridlayout, scrollview required. problem is, scrollview scrolls 2 rows of grids. 2 rows in 1 set of mainrows, if makes sense. want scroll grids contained in layout.

here activity_main.xml:

<?xml version="1.0" encoding="utf-8"?> <scrollview xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="fill_parent" android:layout_height="fill_parent"> <linearlayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" android:id="@+id/parent"> <textview android:id="@+id/textview1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_gravity="center" android:gravity="center" android:text="@string/topeight" android:layout_margintop="5dp"> </textview> </linearlayout> </scrollview>

single_video_grid.xml:

<?xml version="1.0" encoding="utf-8"?> <gridview xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/gridview0" android:layout_width="fill_parent" android:layout_height="fill_parent" android:gravity="center" android:layout_margintop="8dp" android:numcolumns="4"> </gridview>

and code dynamically adding , setting views this:

arraylist<mainrows> rows = jsonvideodatahandler.getrowelements(); (mainrows row : rows) { linearlayout parentlayout = (linearlayout) findviewbyid(r.id.parent); if(row instanceof ads){ // todo implement ads layout }else{ int numberofitems = row.getnumberofitems(); layoutinflater inflater = (layoutinflater) getsystemservice(context.layout_inflater_service); if(numberofitems > 4){ gridview gridview = (gridview) inflater.inflate(r.layout.single_video_grid, null); // if number of vids exceeds 4, 2 rows required. // hence setting 8 imageplaceholders. gridview.setadapter(new imageadapter(this, row, 8)); gridview.setonitemclicklistener(new onitemclicklistener() { public void onitemclick(adapterview<?> parent, view v, int position, long id) { toast.maketext(activity, "haha " + position, toast.length_short).show(); } }); parentlayout.addview(gridview); }else{ gridview gridview = (gridview) inflater.inflate(r.layout.single_video_grid, null); // if number of vids not exceed 4, 1 row required. // hence setting 4 imageplaceholders. gridview.setadapter(new imageadapter(this, row, 4)); gridview.setonitemclicklistener(new onitemclicklistener() { public void onitemclick(adapterview<?> parent, view v, int position, long id) { toast.maketext(activity, "haha " + position, toast.length_short).show(); } }); // linearlayout = (linearlayout) findviewbyid(r.id.parent); parentlayout.addview(gridview); } }

let me know if question not clear enough. appreciate kind of help. give thanks you!

i don't see why exclusively have utilize grid layouts. why not this, create sure framelayout's width screenwidth / 4.

<scrollview> <linearlayout> // vertical < categories { <linerlayout> // horizontal j < videos { <framelayout> // content want show </framelayout> } </linearlayout> } </linearlayout> </scrollview>

android android-linearlayout android-xml android-scrollview android-gridlayout

No comments:

Post a Comment