android - 如何在 Android 中制作这样的自定义搜索栏?

标签 android android-seekbar

我如何在图片下方设计自定义 seekbar

Custom seekbar 1

Custom seekbar 2

有没有人有想法请指导我。提前感谢大家

最佳答案

build.gradle 添加这个依赖

implementation 'com.android.support:recyclerview-v7:27.1.1'

Java 类

 recyclerView = findViewById(R.id.recycler_view);


        LinearLayoutManager layoutManager = new LinearLayoutManager(getBaseContext());
        layoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
        recyclerView.setLayoutManager(layoutManager);

        seekBarList = new ArrayList();
        for (int i = 0; i < 10; i++) {
            seekBarList.add(i);
        }

        SeekBarAdapter seekBarAdapter = new SeekBarAdapter(MainActivity.this, seekBarList);
        recyclerView.setAdapter(seekBarAdapter);

适配器类

public class SeekBarAdapter extends RecyclerView.Adapter<SeekBarAdapter.MyViewHolder> {

        private Context context;
        private ArrayList<Integer> seekList;

        public SeekBarAdapter(MainActivity mainActivity, ArrayList<Integer> barCodeGetList) {
            this.context = mainActivity;
            this.seekList = barCodeGetList;
        }

        @NonNull
        public SeekBarAdapter.MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {

            View itemView = LayoutInflater.from(parent.getContext())
                    .inflate(R.layout.seekbaritem, parent, false);

            return new SeekBarAdapter.MyViewHolder(itemView);
        }

        @Override
        public void onBindViewHolder(@NonNull SeekBarAdapter.MyViewHolder holder, @SuppressLint("RecyclerView") final int position) {

            if (position > 0) {
                holder.img_value_indicater.setVisibility(View.GONE);
            }

            holder.txt_value.setText(seekList.get(position).toString());


        }

        @Override
        public int getItemCount() {
            return seekList.size();
        }

        class MyViewHolder extends RecyclerView.ViewHolder {
            TextView txt_value;
            View view_value;
            ImageView img_value_indicater;
            LinearLayout lay_seekbar_margin;

            MyViewHolder(View view) {
                super(view);
                txt_value = view.findViewById(R.id.txt_value);
                view_value = view.findViewById(R.id.view_value);
                img_value_indicater = view.findViewById(R.id.img_select_indicater);
                lay_seekbar_margin = view.findViewById(R.id.lay_seekmargin);
            }
        }
    }

适配器布局

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_margin="8dp"
    android:orientation="vertical">

    <LinearLayout
        android:id="@+id/lay_seekmargin"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginRight="20dp"
        android:orientation="vertical">

        <View
            android:id="@+id/view_value"
            android:layout_width="1dp"
            android:layout_height="30dp"
            android:layout_gravity="center"
            android:layout_marginLeft="8dp"
            android:layout_marginRight="8dp"
            android:background="#000000" />

        <TextView
            android:id="@+id/txt_value"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginLeft="8dp"
            android:layout_marginRight="8dp" />

        <ImageView
            android:id="@+id/img_select_indicater"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/ic_seek_indicator" />

    </LinearLayout>
</LinearLayout>

关于android - 如何在 Android 中制作这样的自定义搜索栏?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52676299/

相关文章:

android - 插入android日历事件后返回android中的上一个 Activity

android - Groovy Android 插件 : 'groovyx.grooid.groovy-android' or 'groovyx.android'

java - 返回按钮 -> 模拟主页按钮

android - 如何在某个级别停止搜索栏进度?

android - 如何从 fragment 中调用 fragment

android - 自定义 EditTextPreference

java - SeekBar - 无法设置起点

java - Android 的 argb 方法出现问题

android - AppCompatSeekBar 左右填充移除?

android - 如何在 Android 中将 showSeekBarValue 设置为 true?