Android - Last position in seekbar is difficult to reach -


i have seekbar 4 positions, first 3 works well, reach last position have move finger outside seekbar. i'll try put example:

1      2      3      4  ↓      ↓      ↓      ↓  -------------------- |    seekbar     |  -------------------- ↑      ↑      ↑          ↑  1      2      3          4 

the arrows above steps set, arrows below zone have put finger set arrow in position, first 3 positions works zones near them, last must @ position or after (i can't touch after that, because there no screen left).

this seekbar java file

import android.app.activity; import android.content.context; import android.content.contextwrapper; import android.graphics.lineargradient; import android.graphics.shader; import android.graphics.drawable.shapedrawable; import android.graphics.drawable.shapes.roundrectshape; import android.util.attributeset; import android.view.layoutinflater; import android.view.view; import android.view.viewgroup; import android.widget.imageview; import android.widget.linearlayout; import android.widget.relativelayout; import android.widget.seekbar; import android.widget.textview;  import com.company.medical.app.r; import com.company.medical.app.activities.testactivity; import com.company.medical.app.application.app; import com.company.medical.app.domain.entity.profile; import com.company.medical.app.domain.entity.profiletestinfo; import com.company.medical.app.domain.types.gendertype;  import org.androidannotations.annotations.afterviews; import org.androidannotations.annotations.eviewgroup; import org.androidannotations.annotations.viewbyid;  import java.util.list;  @eviewgroup(r.layout.sunburn_seekbar) public class seekbarsunburn extends linearlayout {     private relativelayout intervalnumberslayout = null;     private relativelayout intervalimageslayout = null;      @viewbyid(r.id.face_seekbar)     protected seekbar seekbar;      private int widthmeasurespec = 0;     private int heightmeasurespec = 0;      private seekbarsunburnlistener listener;       gendertype gender;     profile profile;      testactivity context;     profiletestinfo profiletestinfo;      @viewbyid(r.id.cara_piel)     protected imageview carapiel;      public seekbarsunburn(context context, attributeset attrs) {         super(context, attrs);     }      @afterviews     protected void init() {         this.context = (testactivity) getactivity();          profile = app.getcurrentprofile();         gender = profile.getgender();          lineargradient gradient = new lineargradient(0.f,0.f,300.f,0.0f,                 new int[] {util.getcolor(getactivity(), r.color.sun_burn_seekbar_none), util.getcolor(getactivity(), r.color.sun_burn_seekbar_low), util.getcolor(getactivity(), r.color.sun_burn_seekbar_medium), util.getcolor(getactivity(), r.color.sun_burn_seekbar_high)},                 null, shader.tilemode.clamp);          shapedrawable shapedrawable = new shapedrawable(                 new roundrectshape(                         new float[]{50,50,50,50,50,50,50,50},                         null,                         new float[]{50,50,50,50,50,50,50,50}                 )         );         shapedrawable.getpaint().setshader(gradient);          seekbar.setprogressdrawable(shapedrawable);           seekbar.setonseekbarchangelistener(new seekbar.onseekbarchangelistener() {             @override             public void onprogresschanged(seekbar seekbar, int progress, boolean fromuser) {                 if (progress != 0)                     ((testactivity)getcontext()).getprofiletestinfo().setnormalsuntanning(progress);                 if (listener != null)                     listener.onchangeposition(seekbarsunburn.this, progress);             }              @override             public void onstarttrackingtouch(seekbar seekbar) {              }              @override             public void onstoptrackingtouch(seekbar seekbar) {              }         });     }       @override     protected synchronized void onmeasure(int widthmeasurespec, int heightmeasurespec) {         this.widthmeasurespec = widthmeasurespec;         this.heightmeasurespec = heightmeasurespec;          super.onmeasure(widthmeasurespec, heightmeasurespec);     }      @override     protected void onlayout(boolean changed, int l, int t, int r, int b) {         super.onlayout(changed, l, t, r, b);         if (changed){             alignintervals();              measure(widthmeasurespec,heightmeasurespec);             layout(getleft(),gettop(),getright(),getbottom());         }     }      @override     protected void onfinishinflate() {         super.onfinishinflate();          getactivity().getlayoutinflater().inflate(r.layout.sunburn_seekbar, this);     }      private void alignintervals(){         relativelayout globallayout = (relativelayout) getchildat(0);         relativelayout textlayout = (relativelayout) globallayout.getchildat(0);          int widthofseekbarthumb = getseekbarthumbwidth();         int thumboffset = widthofseekbarthumb / 2;          int widthofseekbar = seekbar.getwidth();         int firstintervalwidth = textlayout.getchildat(0).getwidth();         int remainingpaddablewidth = widthofseekbar - firstintervalwidth - widthofseekbarthumb;          int numberofintervals = 4;         int maximumwidthofeachinterval = remainingpaddablewidth / numberofintervals;          alignfirstinterval(thumboffset);          alignintervalsinbetween(maximumwidthofeachinterval);          alignlastinterval(thumboffset, maximumwidthofeachinterval);     }      private void alignfirstinterval(int thumboffset) {         relativelayout globallayout = (relativelayout) getchildat(0);          relativelayout textlayout = (relativelayout) globallayout.getchildat(0);         textview firstintervaltext = (textview) textlayout.getchildat(0);          relativelayout imagelayout= (relativelayout) globallayout.getchildat(1);         imageview firstintervalimage = (imageview) imagelayout.getchildat(1);          firstintervaltext.setpadding(thumboffset, 0 ,0 ,0);         //firstintervalimage.setpadding(thumboffset, 0 ,0 ,0);     }      private void alignintervalsinbetween(int maximumwidthofeachinterval) {         relativelayout globallayout = (relativelayout) getchildat(0);          relativelayout textlayout = (relativelayout) globallayout.getchildat(0);         relativelayout imagelayout= (relativelayout) globallayout.getchildat(1);          int widthofpreviousintervalstext = 0;         int widthofpreviousintervalsimage = 0;          (int index = 1; index < (textlayout.getchildcount() -1 ); index++){             textview textviewinterval = (textview) textlayout.getchildat(index);             int widthoftext = textviewinterval.getwidth();              int leftpadding = math.round(maximumwidthofeachinterval - (widthoftext / 2) - (widthofpreviousintervalstext / 2));             textviewinterval.setpadding(leftpadding, 0, 0, 0);              widthofpreviousintervalstext = widthoftext;         }          (int index = 1; index < (imagelayout.getchildcount() -1 ); index++){             imageview imageviewinterval = (imageview) imagelayout.getchildat(index);             int widthoftext = imageviewinterval.getwidth();              int leftpadding = math.round(maximumwidthofeachinterval - (widthoftext / 2) - (widthofpreviousintervalsimage / 2));             //imageviewinterval.setpadding(leftpadding, 0, 0, 0);              widthofpreviousintervalsimage = widthoftext;         }     }      private void alignlastinterval(int offset, int maximumwidthofeachinterval){         relativelayout globallayout = (relativelayout) getchildat(0);          relativelayout textlayout = (relativelayout) globallayout.getchildat(0);         relativelayout imagelayout= (relativelayout) globallayout.getchildat(1);          int lastindextext = textlayout.getchildcount() - 1;         int lastindeximage = imagelayout.getchildcount() - 1;          textview lastintervaltext = (textview) textlayout.getchildat(lastindextext);         imageview lastintervalimage = (imageview) imagelayout.getchildat(lastindeximage);          int widthoftext = lastintervaltext.getwidth();         int widthofimage = lastintervalimage.getwidth();          int leftpaddingtext = math.round(maximumwidthofeachinterval);         int leftpaddingimage = math.round(maximumwidthofeachinterval - widthofimage - offset);          lastintervaltext.setpadding(leftpaddingtext,0,0,0);         lastintervalimage.setpadding(leftpaddingimage,0,0,0);     }      private int getseekbarthumbwidth() {         return getresources().getdimensionpixeloffset(r.dimen.sunburn_seekbar_thumb);     }      public void setintervals(list<string> intervaltexts, list<integer> intervalimages){         displayintervals(intervaltexts,intervalimages);         seekbar.setmax(intervaltexts.size() -1 );     }      private void displayintervals(list<string> intervaltexts, list<integer> intervalimages) {         int idofpreviousintervaltext = 0;         int idofpreviousintervalimage = 0;          relativelayout globallayout = (relativelayout) getchildat(0);         relativelayout textlayout = (relativelayout) globallayout.getchildat(0);         relativelayout imagelayout= (relativelayout) globallayout.getchildat(1);          if (textlayout.getchildcount() == 0){             (string intervaltext : intervaltexts) {                 textview textviewtext = createinterval(intervaltext);                 textviewtext.setvisibility(visible);                 textviewtext.settextcolor(util.getcolor(context, android.r.color.black));                 aligntextviewtorightofpreviousinterval(textviewtext, idofpreviousintervaltext);                  idofpreviousintervaltext = textviewtext.getid();                  getintervalnumberslayout().addview(textviewtext);             }           }         if (imagelayout.getchildcount() == 0){             (integer intervalimage : intervalimages) {                 imageview imageview = createinterval(intervalimage);                 imageview.setvisibility(gone);                 alignimagetorightofpreviousinterval(imageview, idofpreviousintervalimage);                  idofpreviousintervalimage = imageview.getid();                  getintervalimageslayout().addview(imageview);             }         }     }      private void alignimagetorightofpreviousinterval(imageview imageview, int idofpreviousintervalimage) {         relativelayout.layoutparams params = new relativelayout.layoutparams(                 10, 50         );          if (idofpreviousintervalimage > 0){             params.addrule(relativelayout.right_of, idofpreviousintervalimage);         }          imageview.setlayoutparams(params);     }      private void aligntextviewtorightofpreviousinterval(textview textviewtext, int idofpreviousintervaltext) {         relativelayout.layoutparams params = new relativelayout.layoutparams(                 layoutparams.wrap_content, viewgroup.layoutparams.wrap_content         );          if (idofpreviousintervaltext > 0){             params.addrule(relativelayout.right_of, idofpreviousintervaltext);         }          textviewtext.setlayoutparams(params);     }      private textview createinterval(string intervaltext) {         view textboxview = layoutinflater.from(getcontext()).inflate(r.layout.sunburn_seekbar_labels, null);          textview textview = (textview) textboxview.findviewbyid(r.id.textviewinterval);         textview.setid(view.generateviewid());         textview.settext(intervaltext);         return textview;     }      private imageview createinterval(integer intervalimage) {         view imageboxview = layoutinflater.from(getcontext()).inflate(r.layout.sunburn_seekbar_images, null);          imageview imageview = (imageview) imageboxview.findviewbyid(r.id.imageviewinterval);         imageview.setid(view.generateviewid());         imageview.setcolorfilter(intervalimage);         //imageview.setbackgroundresource(intervalimage);         return imageview;     }      private relativelayout getintervalnumberslayout(){         if (intervalnumberslayout == null)             intervalnumberslayout = (relativelayout)findviewbyid(r.id.seekbar_steps_numbers);          return intervalnumberslayout;     }      private relativelayout getintervalimageslayout(){         if (intervalimageslayout == null)             intervalimageslayout = (relativelayout) findviewbyid(r.id.seekbar_steps_images);         return intervalimageslayout;      }      private activity getactivity() {         context context = getcontext();         while (context instanceof contextwrapper) {             if (context instanceof activity) {                 return (activity)context;             }             context = ((contextwrapper)context).getbasecontext();         }         return null;     }      public void setlistener(seekbarsunburnlistener listener) {         this.listener = listener;     }      public void setprogress(int progress){         seekbar.setprogress(progress);     }      public interface seekbarsunburnlistener{         void onchangeposition(seekbarsunburn seekbarsunburn, int position);     }  } 

and xml

<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android"     android:orientation="horizontal" android:layout_width="match_parent"     android:layout_height="match_parent">      <relativelayout         android:id="@+id/seekbar_steps_numbers"         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:orientation="horizontal"         android:paddingstart="32dp"         android:paddingend="32dp"         android:visibility="visible">      </relativelayout>     <relativelayout         android:id="@+id/seekbar_steps_images"         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:orientation="horizontal"         android:paddingstart="32dp"         android:paddingend="32dp"         android:layout_below="@id/seekbar_steps_numbers"         android:visibility="visible">       </relativelayout>     <seekbar         android:id="@+id/face_seekbar"         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:thumb="@drawable/seekbar_thumb"         android:splittrack="false"         android:thumboffset="0dp"         android:maxheight="40dp"         android:paddingstart="32dp"         android:paddingend="32dp"         android:layout_below="@id/seekbar_steps_images"/>  </relativelayout> 


Comments

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -