android - Modifying Coverflow to use xml file -


in application want modify coverflow can use xml file it. converflow follow. when changed coverflow below

converflow cf = new coverflow(this); 

to

coverflow cf = new coverflow(r.id.coverflowreflect); 

i error: enter image description here the constructor coverflow(int) undefined

i got 3 fixes issue.

the first 1 change constructor

public coverflow(context context) {         super(context);         this.setstatictransformationsenabled(true);     } 

to

public coverflow(int coverflowreflect) {         super(coverflowreflect);         this.setstatictransformationsenabled(true);     } 

but got error in coverflow class saying

the constructor gallery(int) undefined.

here coverflow class:

  public class coverflow extends gallery {          private camera mcamera = new camera();         private int mmaxrotationangle = 0;         private int mmaxzoom = -380;         private int mcoveflowcenter;         private boolean malphamode = true;         private boolean mcirclemode = false;         public coverflow(context context) {             super(context);             this.setstatictransformationsenabled(true);         }         public coverflow(context context, attributeset attrs) {             super(context, attrs);             this.setstatictransformationsenabled(true);         }         public coverflow(context context, attributeset attrs, int defstyle) {             super(context, attrs, defstyle);             this.setstatictransformationsenabled(true);         }         public int getmaxrotationangle() {             return mmaxrotationangle;         }         public void setmaxrotationangle(int maxrotationangle) {             mmaxrotationangle = maxrotationangle;         }         public boolean getcirclemode() {             return mcirclemode;         }         public void setcirclemode(boolean iscircle) {             mcirclemode = iscircle;         }         public boolean getalphamode() {             return malphamode;         }         public void setalphamode(boolean isalpha) {             malphamode = isalpha;         }         public int getmaxzoom() {             return mmaxzoom;         }         public void setmaxzoom(int maxzoom) {             mmaxzoom = maxzoom;         }         private int getcenterofcoverflow() {             return (getwidth() - getpaddingleft() - getpaddingright()) / 2                     + getpaddingleft();         }         private static int getcenterofview(view view) {             return view.getleft() + view.getwidth() / 2;         }         protected boolean getchildstatictransformation(view child, transformation t) {             final int childcenter = getcenterofview(child);             final int childwidth = child.getwidth();             int rotationangle = 0;             t.clear();             t.settransformationtype(transformation.type_matrix);             if (childcenter == mcoveflowcenter) {                 transformimagebitmap((imageview) child, t, 0);             } else {                 rotationangle = (int) (((float) (mcoveflowcenter - childcenter) / childwidth) * mmaxrotationangle);                 if (math.abs(rotationangle) > mmaxrotationangle) {                     rotationangle = (rotationangle < 0) ? -mmaxrotationangle                             : mmaxrotationangle;                 }                 transformimagebitmap((imageview) child, t, rotationangle);             }             return true;         }         /**          * called during layout when size of view has changed. if          * added view hierarchy, you're called old          * values of 0.          *           * @param w          *            current width of view.          * @param h          *            current height of view.          * @param oldw          *            old width of view.          * @param oldh          *            old height of view.          */         protected void onsizechanged(int w, int h, int oldw, int oldh) {             mcoveflowcenter = getcenterofcoverflow();             super.onsizechanged(w, h, oldw, oldh);         }         /**          * transform image bitmap angle passed          *           * @param imageview          *            imageview imageview bitmap want rotate          * @param t          *            transformation          * @param rotationangle          *            angle rotate bitmap          */         private void transformimagebitmap(imageview child, transformation t,                 int rotationangle) {             mcamera.save();             final matrix imagematrix = t.getmatrix();             final int imageheight = child.getlayoutparams().height;             final int imagewidth = child.getlayoutparams().width;             final int rotation = math.abs(rotationangle);             mcamera.translate(0.0f, 0.0f, 100.0f);             // angle of view gets less, zoom in             if (rotation <= mmaxrotationangle) {                 float zoomamount = (float) (mmaxzoom + (rotation * 1.5));                 mcamera.translate(0.0f, 0.0f, zoomamount);                 if (mcirclemode) {                     if (rotation < 40)                         mcamera.translate(0.0f, 155, 0.0f);                     else                         mcamera.translate(0.0f, (255 - rotation * 2.5f), 0.0f);                 }                 if (malphamode) {                     ((imageview) (child)).setalpha((int) (255 - rotation * 2.5));                 }             }             mcamera.rotatey(rotationangle);             mcamera.getmatrix(imagematrix);              imagematrix.pretranslate(-(imagewidth ), -(imageheight / 2));             imagematrix.posttranslate((imagewidth ), (imageheight / 2));              mcamera.restore();         }     }    , made call activity   public class coverflowactivity extends activity {     /** called when activity first created. */     @override     public void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.main);         int pixels = (int) typedvalue.applydimension(typedvalue.complex_unit_dip, 60, getresources().getdisplaymetrics());         coverflow cf = new coverflow(this);         imageadapter ia = new imageadapter(this);         cf.setadapter(ia);         cf.setanimationduration(1000);         cf.setspacing(pixels);         setcontentview(cf);      }      public class imageadapter extends baseadapter {          private int[] mimgs = {                 r.drawable.img1,                 r.drawable.img2,                 r.drawable.img3,                 r.drawable.img4,                 r.drawable.img5,                 r.drawable.img6,                 r.drawable.img7,                 r.drawable.img8         };         context mcontext;          public imageadapter(context context) {             this.mcontext = context;         }         @override         public int getcount() {             return mimgs.length;         }          @override         public object getitem(int position) {             return position;         }          @override         public long getitemid(int position) {             return mimgs[position];          }          @override         public view getview(int position, view convertview, viewgroup parent) {             reflectionimage = new reflectionimage(mcontext);              i.setimageresource(mimgs[position]);             i.setlayoutparams(new coverflow.layoutparams(160, 160));             i.setscaletype(imageview.scaletype.center_inside);             bitmapdrawable drawable = (bitmapdrawable) i.getdrawable();             drawable.setantialias(true);              return i;         }          public float getscale(boolean focused, int offset) {             return math.max(0, 1f/(float)math.pow(2, math.abs(offset)));         }      } } 

the second option change constructor flow

public coverflow(int defstyle) { super(context, attrs, defstyle); ... again coverflow give error. 

the constructor overflow(int) undefined.

does go throughout same issue, mean want activity work xml layout not programmatically now. please

**update: after applying benjamin answer got following error here's log.

note: line 32: setcontentview(coverflow); **

04-18 13:22:42.812: e/androidruntime(4096): fatal exception: main 04-18 13:22:42.812: e/androidruntime(4096): java.lang.runtimeexception: unable start activity componentinfo{com.ufida.coverflow/com.ufida.coverflow.coverflowactivity}: java.lang.illegalstateexception: specified child has parent. must call removeview() on child's parent first. 04-18 13:22:42.812: e/androidruntime(4096):     @ android.app.activitythread.performlaunchactivity(activitythread.java:1651) 04-18 13:22:42.812: e/androidruntime(4096):     @ android.app.activitythread.handlelaunchactivity(activitythread.java:1667) 04-18 13:22:42.812: e/androidruntime(4096):     @ android.app.activitythread.access$1500(activitythread.java:117) 04-18 13:22:42.812: e/androidruntime(4096):     @ android.app.activitythread$h.handlemessage(activitythread.java:935) 04-18 13:22:42.812: e/androidruntime(4096):     @ android.os.handler.dispatchmessage(handler.java:99) 04-18 13:22:42.812: e/androidruntime(4096):     @ android.os.looper.loop(looper.java:130) 04-18 13:22:42.812: e/androidruntime(4096):     @ android.app.activitythread.main(activitythread.java:3687) 04-18 13:22:42.812: e/androidruntime(4096):     @ java.lang.reflect.method.invokenative(native method) 04-18 13:22:42.812: e/androidruntime(4096):     @ java.lang.reflect.method.invoke(method.java:507) 04-18 13:22:42.812: e/androidruntime(4096):     @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:842) 04-18 13:22:42.812: e/androidruntime(4096):     @ com.android.internal.os.zygoteinit.main(zygoteinit.java:600) 04-18 13:22:42.812: e/androidruntime(4096):     @ dalvik.system.nativestart.main(native method) 04-18 13:22:42.812: e/androidruntime(4096): caused by: java.lang.illegalstateexception: specified child has parent. must call removeview() on child's parent first. 04-18 13:22:42.812: e/androidruntime(4096):     @ android.view.viewgroup.addviewinner(viewgroup.java:1976) 04-18 13:22:42.812: e/androidruntime(4096):     @ android.view.viewgroup.addview(viewgroup.java:1871) 04-18 13:22:42.812: e/androidruntime(4096):     @ android.view.viewgroup.addview(viewgroup.java:1851) 04-18 13:22:42.812: e/androidruntime(4096):     @ com.android.internal.policy.impl.phonewindow.setcontentview(phonewindow.java:228) 04-18 13:22:42.812: e/androidruntime(4096):     @ com.android.internal.policy.impl.phonewindow.setcontentview(phonewindow.java:218) 04-18 13:22:42.812: e/androidruntime(4096):     @ android.app.activity.setcontentview(activity.java:1668) 04-18 13:22:42.812: e/androidruntime(4096):     @ com.ufida.coverflow.coverflowactivity.oncreate(coverflowactivity.java:32) 04-18 13:22:42.812: e/androidruntime(4096):     @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1047) 04-18 13:22:42.812: e/androidruntime(4096):     @ android.app.activitythread.performlaunchactivity(activitythread.java:1615) 04-18 13:22:42.812: e/androidruntime(4096):     ... 11 more 

since want xml need find view id try this:

xml:

<?xml version="1.0" encoding="utf-8"?> <linearlayout     xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="fill_parent"     android:layout_height="fill_parent"     android:orientation="vertical" >      <com.yourpackagename.coverflow         android:id="@+id/coverflowid"         android:layout_width="match_parent"         android:layout_height="match_parent" />  </linearlayout> 

activity:

import com.yourpackagename.coverflow; // coverflow class  coverflow coverflow;  public class coverflowactivity extends activity{  //in oncreate this:   coverflow = (coverflow) findviewbyid(r.id.coverflowid);  } 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -