i have been trying write bookshelf app in android using scrollview , tablelayout. have referred other questions on website concerning process of making bookshelf, not find specific answer question. first of all, want know how scale images have passed tablelayout. have tried several methods such shrinkcolumns, stretchcolumns, scalex, scaley. however, none of them seem work or solve problem. there 1 book cut on edge of screen, , under circumstances of stretching , scaling, book cut off. want know if there way autofit number of columns ensure autofits on screen sizes , orientations. there a way in gridview, not able in tablelayout. images scaled in, , want scale them out. please help!
mainactivity.java
package org.example.mylayout; import android.os.bundle; import android.app.activity; import android.view.menu; import android.view.viewgroup.layoutparams; import android.widget.horizontalscrollview; import android.widget.imageview; import android.widget.tablelayout; import android.widget.tablerow; import android.widget.textview; public class mainactivity extends activity { public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); int numrow = 8; int numcol = 15; tablelayout tbllayout = (tablelayout) findviewbyid(r.id.mytablelayout); for(int = 0; < numrow; i++) { horizontalscrollview hsv = new horizontalscrollview(this); hsv.setlayoutparams(new layoutparams(layoutparams.match_parent, layoutparams.match_parent)); tablerow tblrow = new tablerow(this); tablerow.layoutparams myparams = (new tablerow.layoutparams(layoutparams.match_parent, layoutparams.wrap_content)); myparams.rightmargin = 50; tblrow.setlayoutparams((new tablerow.layoutparams(layoutparams.match_parent, layoutparams.wrap_content))); tblrow.setbackgroundresource(r.drawable.row); for(int j = 0; j < numcol; j++) { imageview imageview = new imageview(this); imageview.setscaletype(imageview.scaletype.center_inside); imageview.setlayoutparams(myparams); imageview.setimageresource(r.drawable.book); tblrow.addview(imageview,j); } hsv.addview(tblrow); tbllayout.addview(hsv, i); } } }` activity_main
<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="wrap_content" android:id="@+id/myscrollview" > <tablelayout android:id="@+id/mytablelayout" android:layout_width="fill_parent" android:layout_height="fill_parent" android:padding="0dp" android:scrollbars="none" tools:ignore="scrollviewsize"> </tablelayout> </scrollview> the final emulated version has right book cut off , background of bookshelf extremely scaled. how fix this? lot!
Comments
Post a Comment