java - Horizontal Scrol & different size of images in gridview of android like Windows8 App Tiles -
i have tried android:scrollbars="horizontal"
property not working when increse number of columns 4 10 not show scrolbar disarrange images overlap each other. there anyway slides images in horizontal
instead of vertical
, how can use multiple size of images in grid this
when set column number 4
looks
when increase column numbers column number 10
activity_main.xml code:
<gridview xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/gridview" android:layout_width="fill_parent" android:layout_height="fill_parent" android:columnwidth="150dp" android:numcolumns="auto_fit" android:verticalspacing="10dp" android:horizontalspacing="10dp" android:gravity="center" android:background="@drawable/background" android:scrollbars="horizontal" />
mainactivity.java
package com.example.hellogridview; import android.os.bundle; import android.app.activity; import android.view.menu; import android.widget.adapterview; import android.widget.adapterview.onitemclicklistener; import android.widget.gridview; import android.widget.toast; import android.view.view; public class mainactivity extends activity { @override // protected void oncreate(bundle savedinstancestate) { // super.oncreate(savedinstancestate); // setcontentview(r.layout.activity_main); // } public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); gridview gridview = (gridview) findviewbyid(r.id.gridview); gridview.setadapter(new imageadapter(this)); //gridview.setnumcolumns(10); gridview.setonitemclicklistener(new onitemclicklistener() { public void onitemclick(adapterview<?> parent, view v, int position, long id) { toast.maketext(mainactivity.this, "" + position, toast.length_short).show(); } }); } @override public boolean oncreateoptionsmenu(menu menu) { // inflate menu; adds items action bar if present. getmenuinflater().inflate(r.menu.main, menu); return true; } }
imageadapter.java class
package com.example.hellogridview; import android.content.context; import android.view.view; import android.view.viewgroup; import android.widget.baseadapter; import android.widget.gridview; import android.widget.imageview; public class imageadapter extends baseadapter { private context mcontext; public imageadapter(context c) { mcontext = c; } public int getcount() { return mthumbids.length; } public object getitem(int position) { return null; } public long getitemid(int position) { return 0; } // create new imageview each item referenced adapter public view getview(int position, view convertview, viewgroup parent) { imageview imageview; if (convertview == null) { // if it's not recycled, initialize attributes imageview = new imageview(mcontext); imageview.setlayoutparams(new gridview.layoutparams(300, 300)); imageview.setscaletype(imageview.scaletype.center_crop); imageview.setpadding(8, 8, 8, 8); } else { imageview = (imageview) convertview; } imageview.setimageresource(mthumbids[position]); return imageview; } // references our images private integer[] mthumbids = { r.drawable.sample_2, r.drawable.sample_3, r.drawable.sample_4, r.drawable.sample_5, r.drawable.sample_6, r.drawable.sample_7, r.drawable.sample_0, r.drawable.sample_1, r.drawable.sample_2, r.drawable.sample_3, r.drawable.sample_4, r.drawable.sample_5, r.drawable.sample_6, r.drawable.sample_7, r.drawable.sample_0, r.drawable.sample_1, r.drawable.sample_2, r.drawable.sample_3, r.drawable.sample_4, r.drawable.sample_5, r.drawable.sample_6, r.drawable.sample_7 }; }
what wants :
1) want slides images in horizontal 2) images should different sizes windows8 metrostyle above first image
gridview not meant use different size of cells. have customize tiles layout looks. can use either tablelayout or linearlayout.
Comments
Post a Comment