How to display an Android gridview within a tabbed layout -
hi i'm setting android app , i'm using tabbed interface. i'd 3 tabs, text based tab (about), webkit tab (store) , gridview tab of images (gallery) in gridview tutorial.
i have text , webkit tab working fine, cannot figure out best way format gridview within tab. using tabbed interface tutrial example, declaring tab's content within oncreate() event of main class.
public class woodroid extends tabactivity { /** called when activity first created. */ @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.main); resources res = getresources(); // resource object drawables tabhost tabhost = gettabhost(); // activity tabhost tabhost.setcurrenttab(0); tabhost.tabspec spec; // resusable tabspec each tab intent intent; // reusable intent each tab // create intent launch activity tab (to reused) intent = new intent().setclass(this, aboutactivity.class); // initialize tabspec each tab , add tabhost spec = tabhost.newtabspec("about").setindicator("", res.getdrawable(r.drawable.ic_tab_about)) .setcontent(intent); tabhost.addtab(spec); // same other tabs intent = new intent().setclass(this, storeactivity.class); spec = tabhost.newtabspec("store").setindicator("store", res.getdrawable(r.drawable.ic_tab_store)) .setcontent(intent); tabhost.addtab(spec); intent = new intent().setclass(this, galleryactivity.class); spec = tabhost.newtabspec("gallery").setindicator("gallery", res.getdrawable(r.drawable.ic_tab_gallery)) .setcontent(intent); tabhost.addtab(spec); tabhost.setcurrenttab(0); } }
so in galleryactivity.java have following
public class galleryactivity extends activity { public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); gridview gridview = new gridview(this); gridview.setadapter(new imageadapter(this)); setcontentview(gridview); } }
which interpretation gridview tutorial. thing missing gridview layout definition. seems can force of attributes gridview.setnumcolumns(3);
not allow more flexible looking equivelant /layout/main.xml of gridview version
android:layout_width="fill_parent" android:layout_height="fill_parent" android:columnwidth="90dp" android:numcolumns="auto_fit"
make sure use framelayout, c.f. tabbed example, set android:layout_width="wrap_content" instead of fill_parent , play gravity , weight on each object element until looks how want to.
Comments
Post a Comment