android - GridView isn't being displayed correctly -
i took screenshot of it. displaying weird way:
this code.
the gridadapter:
public class gridviewadapter extends baseadapter { private context mcontext; private arraylist<uri> murls; // references our images public gridviewadapter(context c, arraylist<uri> images) { mcontext = c; this.murls = images; } public int getcount() { return murls.size(); } public object getitem(int position) { return position; } public long getitemid(int position) { return position; } public view getview(int position, view convertview, viewgroup parent) { layoutinflater minflater = (layoutinflater) mcontext.getsystemservice(activity.layout_inflater_service); imageview inflatedimageview = (imageview) minflater.inflate(r.layout.imageview_amb_background, null); //imageview imageview = new imageview(mcontext); inflatedimageview.setimageuri(murls.get(position)); inflatedimageview.setscaletype(imageview.scaletype.center_inside); return inflatedimageview; }
and inflatedimageview
layout inflate, this:
<?xml version="1.0" encoding="utf-8"?> <imageview xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="120dp" android:layout_height="120dp" android:background="@drawable/bgimages" android:maxwidth="120dp" android:padding="5dp"> </imageview>
on other hand, i've gridview in xml file:
<gridview xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:columnwidth="250dp" android:horizontalspacing="5dp" android:numcolumns="3" android:verticalspacing="5dp" > </gridview>
so, inflate gridview, add several uri's (3 exactly) in loop. once added, set adapter gridview:
arraylist<uri> urifotos = new arraylist<uri>(); hashmap<integer, listitem> items = xmllist.getitems(); (int = 0; i<items.size();i++){ listitem itemactual = items.get(i); itemactual.getlogosrc(); urifotos.add(uri.parse(environment.getexternalstoragedirectory().tostring()+rutafinscarpetaclient+itemactual.getlogosrc())); } gridviewinflated.setadapter(new gridviewadapter(this,urifotos)); variablecontent.addview(gridviewinflated);
the images "linked" correctly.
variablecontent
linearlayout inside scrollview, grid should scrollable. can see few things happening:
- height soo big. shouldn't
inflatedimageview
says? - scroll isnt working. well, working i've move finger around , tap several times until works. if stop scrolling i've repeat same proces until reacts again. (solved)
hope guys can me. i've changed lots of layouts, changed widths, heights, , same thing happening.
note image see in gridview, 1200x800px.
edit same code smaller images:
i try set image view size wrap_content :
android:layout_height="wrap_content"
and if need 120dp height, try reset size after having set image src:
inflatedimageview.setimageuri(murls.get(position)); inflatedimageview.setlayoutparams(new gridview.layoutparams(120, 120));
also set scaletype before adding picture (preferably in xml) :
<?xml version="1.0" encoding="utf-8"?> <imageview xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="120dp" android:layout_height="120dp" android:scaletype="centerinside" android:background="@drawable/bgimages" android:maxwidth="120dp" android:padding="5dp"> </imageview>
Comments
Post a Comment