2017-04-21 6 views
8

Ich versuche Gewohnheit zu erreichen seekbar als wie unten Bild
enter image description hereBenutzerdefinierte seekbar android

enter image description here

dafür habe ich den Code unten
I ziehbar für seekbar progressDrawable erstellt haben, lassen Sie mich wissen, wenn Code ist erforderlich, ich werde es hier posten.

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout android:id="@+id/llScale" 
      xmlns:android="http://schemas.android.com/apk/res/android" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_weight="1" 
      android:orientation="vertical" 
      android:paddingBottom="5dp"> 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:background="@color/white" 
    android:orientation="vertical" 
    android:padding="5dp"> 

    <TextView 
     android:id="@+id/sliderText" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:padding="5dp" 
     android:text="Bernard" 
     android:textColor="@color/blue"/> 

    <FrameLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 

     <FrameLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center" 
      android:layout_marginLeft="5dp" 
      android:layout_marginRight="5dp" 
      android:background="@drawable/slider_background" 
      android:padding="3dp"> 

      <SeekBar 
       android:id="@+id/ratingBar" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_gravity="center" 
       android:max="10" 
       android:maxHeight="100dp" 
       android:thumbTintMode="multiply" 
       android:progressDrawable="@drawable/progressbar" 
       android:thumb="@drawable/ic_slider_secondary"/> 

      <TextView 
       android:id="@+id/seekBarHint" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_gravity="center" 
       android:gravity="center" 
       android:text="Drag slider across" 
       android:textColor="@color/dark_gray"/> 
     </FrameLayout> 

     <TextView 
      android:id="@+id/progressText" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:background="@drawable/ic_slider_progress" 
      android:gravity="center" 
      android:textColor="@color/white" 
      android:textStyle="bold"/> 
    </FrameLayout> 
</LinearLayout> 

aber mit obigem Code, was ich bekomme, wie unten Bild ist
hellrote Farbe ist nicht vollständig gefüllt ist, lefts es etwas Platz und am Kreis Ende geht dem boundries aus.

enter image description here

enter image description here

Gradle

compileSdkVersion 23 
buildToolsVersion "23.0.2" 
defaultConfig { 
    applicationId "com.myapp" 
    minSdkVersion 16 
    targetSdkVersion 23 
    multiDexEnabled true 
    versionCode 1 
    versionName "1.0" 
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 
} 

kann jemand bitte helfen Sie mir mit dieser

+0

, was Sie brauchen ein individueller Fortschritt 'Drawable' ist, können Sie es durch den Aufruf' SeekBar # setProgressDrawable (Drawable d) ' – pskink

+0

@pskink: Ich habe eingestellt es in xml android: progressDrawable = "@ drawable/progressbar" –

Antwort

3

ich Ihren Code und erstellten Demo verwendet, in denen ich wie unter 2 verändert haben, :

  1. Set thumbOffset mit entsprechenden Wert für mich 16.5dp arbeitete.

  2. Fügen Sie eine weitere Eigenschaft android hinzu: splitTrack = "false", die dabei hilft, den Bereich um den Daumen zu entfernen.

    <SeekBar 
        android:id="@+id/ratingBar" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:layout_gravity="center" 
        android:maxHeight="100dp" 
        android:progressDrawable="@drawable/progressbar" 
        android:thumb="@drawable/ic_slider_secondary" 
        android:splitTrack="false" 
        android:thumbOffset="16.5dp"/> 
    

Glücklich Coding :)

+0

Vielen Dank Kumpel. :) –