2013-08-23 12 views
9

Chcę Vertical seekBar jak poniżej obrazek (dla Androida 4.O +)). jego w Google Play Music aplikacji.Android Vertical Seek Bar jak Google Play Music App

enter image description here

Próbowałem poniżej sposób: ale nie mogę ustawić wysokość & szerokość

<SeekBar 
    android:id="@+id/seekBar1" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:rotation="270" 
    /> 

chcę jak poniżej:

enter image description here

teraz ja użyłem tego Stack Answer, ale jest to zbyt trudne n wiele różnych pionowych funkcji wyszukiwania.

Szukam lepszej drogi niż to.


EDIT:

Użyłem poniżej kod z iDroid Explorer's answer spróbować wyświetlić pionowy pasek przewijania:

private void setupEqualizerFxAndUI() { 

     for (short i = 0; i < 5; i++) { 

      LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
        ViewGroup.LayoutParams.MATCH_PARENT, 
        ViewGroup.LayoutParams.MATCH_PARENT); 
      layoutParams.weight = 3; 

      LinearLayout row = new LinearLayout(this); 
      row.setOrientation(LinearLayout.VERTICAL); 
      row.setLayoutParams(layoutParams); 

      TextView minDbTextView = new TextView(this); 
      minDbTextView.setLayoutParams(new ViewGroup.LayoutParams(
        ViewGroup.LayoutParams.WRAP_CONTENT, 
        ViewGroup.LayoutParams.WRAP_CONTENT)); 
      minDbTextView.setText(i + " dB"); 

      TextView maxDbTextView = new TextView(this); 
      maxDbTextView.setLayoutParams(new ViewGroup.LayoutParams(
        ViewGroup.LayoutParams.WRAP_CONTENT, 
        ViewGroup.LayoutParams.WRAP_CONTENT)); 
      maxDbTextView.setText(i + " dB"); 

      LinearLayout.LayoutParams layoutParams1 = new LinearLayout.LayoutParams(
        ViewGroup.LayoutParams.MATCH_PARENT, 
        ViewGroup.LayoutParams.WRAP_CONTENT); 
      layoutParams1.weight = 2; 

      SeekBar bar = new SeekBar(this); 
      bar.setLayoutParams(layoutParams1); 
      bar.setMax(100); 
      bar.setProgress(20); 
      bar.setRotation(270); 
      bar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { 
       public void onProgressChanged(SeekBar seekBar, int progress, 
         boolean fromUser) { 

       } 

       public void onStartTrackingTouch(SeekBar seekBar) { 
       } 

       public void onStopTrackingTouch(SeekBar seekBar) { 
       } 
      }); 

      row.addView(minDbTextView); 
      row.addView(bar); 
      row.addView(maxDbTextView); 

      mLinearLayout.addView(row); 

     } 
    } 

ale wygląda następująco: wskaźnik nie pokazuje.

enter image description here

jeśli mogę użyć tylko jednego SeekBar wtedy jego wygląd jak poniżej:

enter image description here

go samego jak użytku: android:rotation="270" w pliku układu.

+0

utworzyć klasę niestandardową, która rozciąga SeekBar, a następnie utworzyć wiele pionową SeekBar chcesz –

+0

@Dhawal Sodha: Czy możesz mi powiedzieć, które stoją trudności podczas realizacji mojego kodu? czy mój kod działa dla ciebie? –

+0

Korzystanie z natywnych zdarzeń dotykowych z Androida działa całkiem dobrze, aby budować własne widoki za pomocą funkcji przeciągania, używając pojęć "pozycja początkowa", "delta" i "pozycja końcowa". Interfejs API systemu Android jest bardzo przejrzysty i stabilny podczas obsługi zdarzeń dotykowych, dzięki czemu wymagana logika jest nie myślenia. –

Odpowiedz

6

Czy sprawdziłeś kod przykładowy Androida: AudioFXDemo? Jeśli nie, sprawdź to i sprawdź, czy jest to pomocne dla Ciebie, czy nie.

Istnieje Korektor graficzny, który jest taki sam jak w aplikacji Muzyka Google.

zobacz poniżej kodu w tym Demo Przykład:

private void setupEqualizerFxAndUI() { 
     // Create the Equalizer object (an AudioEffect subclass) and attach it to our media player, 
     // with a default priority (0). 
      try { 
      System.out.println("setupEqualizerFxAndUI eEqualizer is: "+mEqualizer); 
      System.out.println("setupEqualizerFxAndUI mIRemoteService: "+mIRemoteService); 
      mEqualizer = new Equalizer(0,mIRemoteService.getAudioSessionId()); 
     } catch (IllegalStateException e) { 
      e.printStackTrace(); 
     } catch (IllegalArgumentException e) { 
      e.printStackTrace(); 
     } catch (UnsupportedOperationException e) { 
      e.printStackTrace(); 
     } catch (RemoteException e) { 
      e.printStackTrace(); 
     } catch (RuntimeException e) { 
      e.printStackTrace(); 
     } // Error in this line 

     if(onOffBtn.isChecked()){ 
      mEqualizer.setEnabled(true); 
     } 

     short bands = 5 ; 
     //System.out.println("bands are: "+bands); 

     LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,LinearLayout.LayoutParams.WRAP_CONTENT); 
     params.weight = 1; 

     LinearLayout newOne = new LinearLayout(this); 
     newOne.setLayoutParams(params); 
     newOne.setOrientation(LinearLayout.HORIZONTAL); 

     final short minEQLevel = mEqualizer.getBandLevelRange()[0]; 
     final short maxEQLevel = mEqualizer.getBandLevelRange()[1]; 

     //System.out.println("Minimum value::: "+minEQLevel); 
     //System.out.println("Maximum value::: "+maxEQLevel); 

     //VerticalSeekBar[] bar = new VerticalSeekBar[5]; 

     for (short i = 0; i < bands; i++) { 
      final short band = i; 

      /* TextView freqTextView = new TextView(this); 
      freqTextView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)); 
      freqTextView.setGravity(Gravity.CENTER_HORIZONTAL); 
      freqTextView.setText((mEqualizer.getCenterFreq(band)/1000) + " Hz"); 
      newOne.addView(freqTextView);*/ 

      LinearLayout row = new LinearLayout(this); 

      row.setOrientation(LinearLayout.VERTICAL); 

      TextView minDbTextView = new TextView(this); 
      minDbTextView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,ViewGroup.LayoutParams.WRAP_CONTENT)); 
      minDbTextView.setText((minEQLevel/100) + " dB"); 
      minDbTextView.setTextColor(0xff000000); 

      TextView maxDbTextView = new TextView(this); 
      maxDbTextView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)); 
      maxDbTextView.setText((maxEQLevel/100) + " dB"); 
      maxDbTextView.setTextColor(0xff000000); 

      LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, 300); 
      layoutParams.setMargins(0, 10, 0, 10); 

//-------------------------- 

      // setClassicTone(maxEQLevel, minEQLevel); 

      VerticalSeekBar bar = new VerticalSeekBar(this); 

      bar = new VerticalSeekBar(this); 
      bar.setLayoutParams(layoutParams); 
      bar.setMax(maxEQLevel - minEQLevel); 
      bar.setProgress(mEqualizer.getBandLevel(band)); 
      //bar.setMax(3000); 
      //bar.setProgress(mEqualizer.getBandLevel(band)+1500); 
      bar.setPadding(0, 10, 0, 10); 

      //bar.setProgressDrawable(R.drawable.scrubber_progress_horizontal_holo_light); 
      bar.setProgressDrawable(getResources().getDrawable(R.drawable.scrubber_progress_horizontal_holo_light)); 
      bar.setThumb(getResources().getDrawable(R.drawable.scrubber_control_selector_holo)); 
      //System.out.println("Progress:::"+(mEqualizer.getBandLevel(band))); 
      //bar[i].setProgress((maxEQLevel-minEQLevel)/2); 
      mEqualizer.setBandLevel(band,(short) ((maxEQLevel-minEQLevel))); 
      //System.out.println("Presets are: "+mEqualizer.getNumberOfPresets()+" And name is: "+mEqualizer.getPresetName(i)); 

      //mEqualizer.setBandLevel(band, level) 
      bar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { 
       public void onProgressChanged(SeekBar seekBar, int progress,boolean fromUser) { 
        System.out.println("Seek bar change "); 
        presetsSpinner.setSelection(0); 
        mEqualizer.setBandLevel(band, (short) (progress + minEQLevel)); 

       } 

       public void onStartTrackingTouch(SeekBar seekBar) {} 
       public void onStopTrackingTouch(SeekBar seekBar) {} 
      }); 

      row.addView(maxDbTextView); 
      row.addView(bar); 
      row.addView(minDbTextView); 

      newOne.addView(row, params); 
     } 

     equalizerLayout.addView(newOne); 
    } 

A VerticalSeekBar jest klasa, jak poniżej:

import android.content.Context; 
import android.graphics.Canvas; 
import android.util.AttributeSet; 
import android.view.MotionEvent; 
import android.widget.SeekBar; 

public class VerticalSeekBar extends SeekBar { 

    public VerticalSeekBar(Context context) { 
     super(context); 
    } 

    public VerticalSeekBar(Context context, AttributeSet attrs, int defStyle) { 
     super(context, attrs, defStyle); 
    } 

    public VerticalSeekBar(Context context, AttributeSet attrs) { 
     super(context, attrs); 
    } 

    protected void onSizeChanged(int w, int h, int oldw, int oldh) { 
     super.onSizeChanged(h, w, oldh, oldw); 
    } 

    @Override 
    protected synchronized void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 
     super.onMeasure(heightMeasureSpec, widthMeasureSpec); 
     setMeasuredDimension(getMeasuredHeight(), getMeasuredWidth()); 
    } 

    protected void onDraw(Canvas c) { 
     c.rotate(-90); 
     c.translate(-getHeight(), 0); 

     super.onDraw(c); 
    } 

    @Override 
    public boolean onTouchEvent(MotionEvent event) { 
     if (!isEnabled()) { 
      return false; 
     } 

     switch (event.getAction()) { 
      case MotionEvent.ACTION_DOWN: 
      case MotionEvent.ACTION_MOVE: 
      case MotionEvent.ACTION_UP: 
       setProgress(getMax() - (int) (getMax() * event.getY()/getHeight())); 
       onSizeChanged(getWidth(), getHeight(), 0, 0); 

       break; 

      case MotionEvent.ACTION_CANCEL: 
       break; 
     } 
     return true; 
    } 
} 

Nadzieja Powyższy kod pomóc. Jeśli nie, daj mi znać.

... :) Enjoy Coding kod

+0

Dzięki za odpowiedź, użyłem twojego kodu. ale pokazuje wskaźnik, proszę sprawdź moje edytowane pytanie. –

+0

możesz usunąć bar.setRotation (270); i zobacz wynik. Nie mam czegoś takiego w moim kodzie. –

+0

moje pytanie dotyczy pionowego paska wyszukiwania. jeśli usunę bar.setRotation (270); następnie pokazuje poziomo. –

2

Najwyraźniej korektor nie jest częścią Google Play Music, lecz oddzielna aplikacja nazywa MusicFX (com.android.musicfx): Kod

I/ActivityManager(536): START u0 {act=android.media.action.DISPLAY_AUDIO_EFFECT_CONTROL_PANEL cmp=com.android.musicfx/.Compatibility$Redirector (has extras)} from pid 4800 
I/ActivityManager(536): START u0 {act=android.media.action.DISPLAY_AUDIO_EFFECT_CONTROL_PANEL flg=0x2000000 cmp=com.android.musicfx/.ActivityMusic (has extras)} from pid 4867 
I/ActivityManager(536): Displayed com.android.musicfx/.ActivityMusic: +293ms (total +315ms) 

Źródłem MusicFX jest dostępny od Android repository.

Mam nadzieję, że to pomoże.

9

iDroid Explorer jest wielki i bardzo mi pomogło coraz zadanie, jednak brakuje niektórych części. Oto moja zhakowana wersja, działa ona dobrze dla mnie i mam nadzieję, że to też zrobi.

public class VerticalSeekBar extends SeekBar { 

    protected OnSeekBarChangeListener changeListener; 
    protected int x, y, z, w; 

    public VerticalSeekBar(Context context) { 
     super(context); 
    } 

    public VerticalSeekBar(Context context, AttributeSet attrs, int defStyle) { 
     super(context, attrs, defStyle); 
    } 

    public VerticalSeekBar(Context context, AttributeSet attrs) { 
     super(context, attrs); 
    } 

    @Override 
    protected synchronized void onSizeChanged(int w, int h, int oldw, int oldh) { 
     super.onSizeChanged(h, w, oldh, oldw); 

     this.x = w; 
     this.y = h; 
     this.z = oldw; 
     this.w = oldh; 
    } 

    @Override 
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 
     super.onMeasure(heightMeasureSpec, widthMeasureSpec); 
     setMeasuredDimension(getMeasuredHeight(), getMeasuredWidth()); 
    } 

    @Override 
    protected void onDraw(Canvas c) { 
     c.rotate(-90); 
     c.translate(-getHeight(), 0); 

     super.onDraw(c); 
    } 

    @Override 
    public boolean onTouchEvent(MotionEvent event) { 
     if (!isEnabled()) { 
      return false; 
     } 

     switch (event.getAction()) { 
      case MotionEvent.ACTION_DOWN: 
       setSelected(true); 
       setPressed(true); 
       if (changeListener != null) changeListener.onStartTrackingTouch(this); 
       break; 
      case MotionEvent.ACTION_UP: 
       setSelected(false); 
       setPressed(false); 
       if (changeListener != null) changeListener.onStopTrackingTouch(this); 
       break; 
      case MotionEvent.ACTION_MOVE: 
       int progress = getMax() - (int) (getMax() * event.getY()/getHeight()); 
       setProgress(progress); 
       onSizeChanged(getWidth(), getHeight(), 0, 0); 
       if (changeListener != null) changeListener.onProgressChanged(this, progress, true); 
       break; 

      case MotionEvent.ACTION_CANCEL: 
       break; 
     } 
     return true; 
    } 

    @Override 
    public synchronized void setOnSeekBarChangeListener(OnSeekBarChangeListener listener) { 
     changeListener = listener; 
    } 

    @Override 
    public synchronized void setProgress(int progress) { 
     if (progress >= 0) 
      super.setProgress(progress); 

     else 
      super.setProgress(0); 
     onSizeChanged(x, y, z, w); 
     if (changeListener != null) changeListener.onProgressChanged(this, progress, false); 
    } 
} 
Powiązane problemy