English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Controle deslizante de faixa dinâmica de valor fixo implementado no Android

Vamos ver o efeito primeiro:

1. Passos para adicionar bibliotecas dependentes

1.Arquivo gradle do projeto com as seguintes alterações

allprojects {
  repositories {
   ...
   maven { url "https://jitpack.io" }
  }
 }

2.Adicionar a biblioteca dependente da versão mais recente, conforme mostrado à direita, altere o final da versão (porque às vezes eu atualizo a versão e esqueço de alterar o readme)

dependencies {
   compile 'com.github.Brioal:BrioalSetting:1.0'
   ////Por exemplo, a versão mais recente acima é1.1, então basta1.0 para1.1já pode usar a versão mais recente
 }

Segundo, etapas de uso:

1.arquivo de layout XML

Durante o uso real, descobri que se usado junto com outros componentes, o evento de deslize se torna ineficaz, ainda não descobri como resolver isso no código, nem configurar focus funciona, a solução temporária é adicionar um layout pai ao componente e não incluir outros componentes, conforme abaixo:

<LinearLayout
  android:id="@"+id/layout"
android:layout_centerInParent="true"
  android:layout_width="match_parent"
  android:layout_height="wrap_content">
  <com.brioal.rangeseek.view.RangeBar
   android:id="@"+id/main_container"
   android:layout_width="match_parent"
   android:layout_height="wrap_content"
   android:layout_centerInParent="true"/>
 </LinearLayout>

2.Configuração de código

mRangeBar = (RangeBar) findViewById(R.id.main_container);
   //Adicionar origem de dados
  final List<RangeEntity> list = new ArrayList<>();
  //Os textos a serem exibidos e os valores reais, respectivamente, são do tipo String e Object
  list.add(new RangeEntity("15℃", 15));
  list.add(new RangeEntity("18℃", 18));
  list.add(new RangeEntity("21℃", 21));
  list.add(new RangeEntity("24℃", 24));
  list.add(new RangeEntity("27℃", 27));
  list.add(new RangeEntity("30℃", 30));
  //Definir origem de dados
  mRangeBar.setValues(list);
  //Adicionar ouvinte de mudança de faixa
  mRangeBar.addOnRangeChangedListener(new OnRangeChangedListener() {
   @Override
   public void selected(int startIndex, int endIndex) {
   //The data obtained is the index of the start and end in the List
    mTvMin.setText(list.get(startIndex).getValue() + ");
    mTvMax.setText(list.get(endIndex).getValue() + ");
   }
  });

3.Methods provided for custom views

Method Function
void addOnRangeChangedListener(OnRangeChangedListener listener) Set the event listener
void setLineColor(int lineColor) Set the line color in the middle
void setLineWidth(int lineWidth) Set the line width in the middle
void setCircleColor(int circleColor) Set the border color of the point
void setCircleRadius(int circleRadius) Set the radius of the point
void setCircleWidth(int circleWidth) Set the line width of the point
void setCenterColor(int centerColor) Set the fill color of the selected point
void setPointColor(int pointColor) Set the fill color of the cursor
void setStartIndex(int startIndex) Set the selected starting index
int getStartIndex() Obtain the selected starting index
void setEndIndex(int endIndex) Set the terminating index
int getEndIndex() Obtain the terminating index

Summary

This is the end of this article, I hope this article can bring some help to everyone's learning or work, if you have any questions, please leave a message for communication.

Você também pode gostar