我这里用到的是自定义HorizontalScrollView实现简单的类似Wheelview效果,不多说先看代码.
先看布局:
<vgaw.com.WheelView
android:id="@+id/wv"
android:layout_width="match_parent"
android:layout_height="100dp"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" >
<LinearLayout
android:id="@+id/ll_camera_aperture"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:orientation="horizontal"></LinearLayout>
</vgaw.com.dialogfragment.WheelView>
自定义WheelView继承HorizontalScrollView.主要逻辑:
public class WheelView extends HorizontalScrollView {
private static final int CHECK_STOP_DELAY = 10;
private int itemCount = 5;
private int showItemCount = 5;
private int itemPadding = 0;
private int width;
private int itemWidth;
private WheelViewAdapter adapter;
private LinearLayout rootView;
private int currentposstion;
public WheelVi