public class SecodeActivity extends AppCompatActivity {
SpinnerX spinnerX;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_seconde);
spinnerX = new SpinnerX(this);
spinnerX.setData(Arrays.asList("菜单1", "菜单2", "菜单3", "菜单4", "菜单5", "菜单6"));
spinnerX.setOnSpinnerClickListener(new SpinnerX.OnSpinnerClickListener() {
@Override
public void onMenu(String context, int position) {
Toast.makeText(SecodeActivity.this, position + context, Toast.LENGTH_SHORT).show();
}
});
}
public void open(View view) {
spinnerX.setAnchorView(view);
spinnerX.show();
}
}
1. 限制高度
// 未做限制
SpinnerX spinnerX = new SpinnerX(this);
// 限制高度
SpinnerX spinnerX = new SpinnerX(this, true);
未设置限制
设置了限制