Adding Dynamically ImageViews to horizontal scrollview in android -
i'm trying show images dynamically string id , want display in horizontal scroll-view have 13 cards can't fit on screen
here code working fine want in horizontal scroll view
int resid = getresources().getidentifier(resourcename, "id", getpackagename()); imageview im = (imageview) findviewbyid(resid); context context = im.getcontext(); int id = context.getresources().getidentifier(resourcename, "drawable", context.getpackagename()); relativelayout.layoutparams lp = new relativelayout.layoutparams(im.getlayoutparams()); lp.setmargins(counter * 43, 0, 0, 0);//left,right,top,bottom im.setlayoutparams(lp); im.setimageresource(id); im.setonclicklistener(this); counter++; } mp = mediaplayer.create(getapplicationcontext(), r.raw.clicksound); }![enter image description here][2]
as per requirement suggest recyclerview comes library have add , use recyclerview horizontal orientation refer link below. https://developer.android.com/training/material/lists-cards.html
or can dynamically below
here can add linear horizontal layout inside scrollview id imgcontainer can
create image view dynamically , add linear layout.
for(int i=0;i<10;i++) { //create imageview here , setbg imageview imageview = new imageview(this); imageview.setimageresource(r.drawable.ic_launcher); ((linearlayout) findviewbyid(r.id.imgcontainer)).addview( imageview, i); }
Comments
Post a Comment