gpt4 book ai didi

android - 如何设置 wheelView 项

转载 作者:行者123 更新时间:2023-11-29 15:42:56 25 4
gpt4 key购买 nike

我找到这个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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com