Android Studio中类似JSlider的Java
如何在Android Studio中添加JSliderAndroid Studio中类似JSlider的Java,java,android-studio,Java,Android Studio,如何在Android Studio中添加JSlider 看起来是这样的:您可能正在寻找搜索栏 请参阅以下链接上的文档: 如果你想为你的SeekBar定制背景,可以添加一个可绘制的,我命名为我的定制进度。我在下面用xml将其添加到SeekBar后台 可绘制xml <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" > <gradient
看起来是这样的:您可能正在寻找搜索栏 请参阅以下链接上的文档: 如果你想为你的SeekBar定制背景,可以添加一个可绘制的,我命名为我的定制进度。我在下面用xml将其添加到SeekBar后台 可绘制xml
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<gradient
android:startColor="#1F1F20"
android:endColor="#271313"
android:angle="0"/>
<corners
android:radius="10dp"/>
</shape>
<SeekBar
android:id="@+id/simpleSeekBar"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="@drawable/custom_progress"
android:max="100" />
欢迎来到SO社区。。Android框架中没有提供这种功能的东西,您必须使用;您也可以考虑建立自定义<代码>搜索栏Value.< 下面是一个演示,通过使用带有加权内部
文本视图的线性布局
可以实现什么,每个视图代表一个标签,您希望为SeekBar
的值指示该标签
注意:我对SeekBar使用任意值
- 最小值为0
- 最多100个
- 十步
布局
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<SeekBar
android:id="@+id/seekbar"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:paddingStart="0dp"
android:paddingLeft="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<LinearLayout
android:layout_width="300dp"
android:layout_height="wrap_content"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/seekbar">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="0" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="25" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="50" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="75" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="100" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
演示
也可以考虑第三方库:
您还可以查看一篇有用的文章不,它没有帮助。我不想要一个简单的seekBar,我想要在seekBar中有一个单独的指针(如图所示),而不是指示下面数字的圆形指针。@SKumar那么您到目前为止尝试了什么呢?让我们继续。。。看看
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<SeekBar
android:id="@+id/seekbar"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:paddingStart="0dp"
android:paddingLeft="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<LinearLayout
android:layout_width="300dp"
android:layout_height="wrap_content"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/seekbar">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="0" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="25" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="50" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="75" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="100" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
SeekBar seekBar = findViewById(R.id.seekbar);
seekBar.setEnabled(true);
seekBar.setProgress(0);
seekBar.incrementProgressBy(10);
seekBar.setMax(100);
seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean
fromUser) {
seekBar.setProgress((progress / 10) * 10);
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});