Screenshot_20201121-015319.jpg

  1. public class SecodeActivity extends AppCompatActivity {
  2. SpinnerX spinnerX;
  3. @Override
  4. protected void onCreate(@Nullable Bundle savedInstanceState) {
  5. super.onCreate(savedInstanceState);
  6. setContentView(R.layout.activity_seconde);
  7. spinnerX = new SpinnerX(this);
  8. spinnerX.setData(Arrays.asList("菜单1", "菜单2", "菜单3", "菜单4", "菜单5", "菜单6"));
  9. spinnerX.setOnSpinnerClickListener(new SpinnerX.OnSpinnerClickListener() {
  10. @Override
  11. public void onMenu(String context, int position) {
  12. Toast.makeText(SecodeActivity.this, position + context, Toast.LENGTH_SHORT).show();
  13. }
  14. });
  15. }
  16. public void open(View view) {
  17. spinnerX.setAnchorView(view);
  18. spinnerX.show();
  19. }
  20. }

1. 限制高度

  1. // 未做限制
  2. SpinnerX spinnerX = new SpinnerX(this);
  3. // 限制高度
  4. SpinnerX spinnerX = new SpinnerX(this, true);

未设置限制
微信图片_20201211123108.jpg微信图片_202012111232201.jpg
设置了限制
微信图片_202012111231081.jpg微信图片_20201211123220.jpg