2013-07-14 29 views
5

Bir arama çubuğunu, önceden belirlenmiş bir zamanda, 30sec'te arama çubuğuna bir nokta koymam gerektiği şekilde özelleştirmem gerekiyor. Bu süre her video için değişir, böylece nasıl belirli bir ikinciandroid arama çubuğu özelleştirme,

+0

Özel görünüm oluşturmayı denediniz mi? – sandrstar

+0

@sandrstar İstek çubuğu için özel görünümü? bir sınıf uzanan arama çubuğu? Bu noktaları nasıl yerleştireceğiniz hakkında çok fazla fikriniz yok. Herhangi bir yardım takdir, teşekkürler – user2558496

cevap

16

Here're bazı olasılıklar aramak çubuğunda bir nokta noktası yerleştirmek için: sadece SeekBar yukarıda

  1. koyun 'nokta' görünümü bir. Burada ayrıntılı olarak açıklamayacaktır, çünkü bu önemsiz android düzeni görevidir;
  2. gibi SeekBar uzatın aşağıdaki ( this good explanation about custom views bakınız):

    /** 
    * Seek bar with dots on it on specific time/percent 
    */ 
    public class DottedSeekBar extends SeekBar { 
    
        /** Int values which corresponds to dots */ 
        private int[] mDotsPositions = null; 
        /** Drawable for dot */ 
        private Bitmap mDotBitmap = null; 
    
        public DottedSeekBar(final Context context) { 
         super(context); 
         init(null); 
        } 
    
        public DottedSeekBar(final Context context, final AttributeSet attrs) { 
         super(context, attrs); 
         init(attrs); 
        } 
    
        public DottedSeekBar(final Context context, final AttributeSet attrs, final int defStyle) { 
         super(context, attrs, defStyle); 
         init(attrs); 
        } 
    
        /** 
        * Initializes Seek bar extended attributes from xml 
        * 
        * @param attributeSet {@link AttributeSet} 
        */ 
        private void init(final AttributeSet attributeSet) { 
         final TypedArray attrsArray = getContext().obtainStyledAttributes(attributeSet, R.styleable.DottedSeekBar, 0, 0); 
    
         final int dotsArrayResource = attrsArray.getResourceId(R.styleable.DottedSeekBar_dots_positions, 0); 
    
         if (0 != dotsArrayResource) { 
          mDotsPositions = getResources().getIntArray(dotsArrayResource); 
         } 
    
         final int dotDrawableId = attrsArray.getResourceId(R.styleable.DottedSeekBar_dots_drawable, 0); 
    
         if (0 != dotDrawableId) { 
          mDotBitmap = BitmapFactory.decodeResource(getResources(), dotDrawableId); 
         } 
        } 
    
        /** 
        * @param dots to be displayed on this SeekBar 
        */ 
        public void setDots(final int[] dots) { 
         mDotsPositions = dots; 
         invalidate(); 
        } 
    
        /** 
        * @param dotsResource resource id to be used for dots drawing 
        */ 
        public void setDotsDrawable(final int dotsResource) { 
         mDotBitmap = BitmapFactory.decodeResource(getResources(), dotsResource); 
         invalidate(); 
        } 
    
        @Override 
        protected synchronized void onDraw(final Canvas canvas) { 
         super.onDraw(canvas); 
    
         final int width = getMeasuredWidth(); 
         final int step = width/getMax(); 
    
         if (null != mDotsPositions && 0 != mDotsPositions.length && null != mDotBitmap) { 
          // draw dots if we have ones 
          for (int position : mDotsPositions) { 
           canvas.drawBitmap(mDotBitmap, position * step, 0, null); 
          } 
         } 
        } 
    } 
    

    res/values/attrs.xml özel attrs unutmayın:

    <resources> 
        <declare-styleable name="DottedSeekBar"> 
         <attr name="dots_positions" format="reference"/> 
         <attr name="dots_drawable" format="reference"/> 
        </declare-styleable> 
    </resources> 
    

    Ve aşağıdaki kodu kullanarak:

    setContentView(R.layout.main); 
    
    final DottedSeekBar bar = (DottedSeekBar) findViewById(R.id.seekBar); 
    
    bar.setDots(new int[] {25, 50, 75}); 
    bar.setDotsDrawable(R.drawable.dot); 
    
    Main.xml düzeniyle

    :

    <LinearLayout 
         xmlns:android="http://schemas.android.com/apk/res/android" 
         xmlns:custom="http://schemas.android.com/apk/res/com.example.TestApp" 
         android:orientation="vertical" 
         android:layout_width="match_parent" 
         android:layout_height="match_parent"> 
    
        <com.example.TestApp.DottedSeekBar 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:id="@+id/seekBar" /> 
    </LinearLayout> 
    

    ya da sadece tek main.xml:

    <LinearLayout 
         xmlns:android="http://schemas.android.com/apk/res/android" 
         xmlns:custom="http://schemas.android.com/apk/res/com.example.TestApp" 
         android:orientation="vertical" 
         android:layout_width="match_parent" 
         android:layout_height="match_parent"> 
    
        <com.example.TestApp.DottedSeekBar 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:id="@+id/seekBar" 
         custom:dots_positions="@array/dots" 
         custom:dots_drawable="@drawable/dot" /> 
    </LinearLayout> 
    

    Aşağıdaki görüntüyü elde edebilir: enter image description here

  3. fazla fikir için this example bakınız; Belirli 'zamanında' üzerine noktalar koyarak İlişkin

: o zaman ilişkili bir mantık sağlamak için You kalmış böylece SeekBar, zamanı değil.

İlgili konular