android - 如何设置 wheelView 项

标签 android custom-view

我找到这个https://github.com/LukeDeighton/WheelView Github 中的项目,我不知道如何在 wheelView 的不同位置设置不同的项目。我想添加两个项目(ArrayList 列表) 谁能阻止我??

这是我的代码:

public class MainActivity extends AppCompatActivity {

private WheelView wheelView;
private ArrayList<Drawable> list;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    //This is the items I want to add
    list = new ArrayList<>();
    list.add(getResources().getDrawable(R.drawable.loader));
    list.add(getResources().getDrawable(R.drawable.twitter));
    ////

    wheelView = (WheelView) findViewById(R.id.wheelView);

    wheelView.setAdapter(new WheelAdapter() {

        @Override
        public Drawable getDrawable(int position) {

            return ...;
        }

        @Override
        public int getCount() {
            return (int)wheelView.getItemCount();
        }

        @Override
        public Object getItem(int position) {
            return 0;
        }
    });

}
}

这是 xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.roashviz.giftest2.MainActivity">



<com.lukedeighton.wheelview.WheelView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/wheelView"
    app:wheelColor="@color/colorAccent"
    app:rotatableWheelDrawable="true"
    app:selectionAngle="270.0"
    app:wheelPosition=""
    app:wheelOffsetY="0dp"
    app:repeatItems="true"
    app:wheelRadius="150dp"
    app:wheelItemCount="2"
    app:wheelPadding="13dp"
    app:wheelItemRadius="43dp"
    android:layout_alignParentBottom="true" />

谢谢!! :)

最佳答案

我猜你需要像这样更新你的代码,我没试过,但它应该可以工作

wheelView.setAdapter(new WheelAdapter() {

@Override
public Drawable getDrawable(int position) {

    return list.get(position);
}

@Override
public int getCount() {
    return list.size();
}

@Override
public Object getItem(int position) {
    return list.get(position);
}
});

关于android - 如何设置 wheelView 项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37556637/

相关文章:

android - 无法在设备 : Too many open files 上安装 ClubDangoV2Released.apk

java - Android 画图应用程序数组

java - 更新Android的Sqlite和ContentValues中的值

android - 具有不同边距/填充的移动和桌面中的相同 CSS

java - Android 中的 View 占据整个屏幕 - 如何告诉 Canvas 尊重 View 的限制?

android - 返回到具有自定义 View 的 Activity 时,Invalidate 无法调用 onDraw

java - 从 Facebook SDK android 获取用户电子邮件

iOS >> Quart Core 'Corner Radius' 不影响自定义 View 中的导航栏

ios - NavigationController titleView 中的自定义 UIView。如何让按钮在我的 View Controller 中触发操作