下拉列表如果下面没位置了就变成上拉了
1.数据
String[] giftNumber = {"1", "10", "66", "99"};
2.适配器和下拉列表监听
//价格适配器
spinnerNumber.setAdapter(new ArrayAdapter<>(mContext, R.layout.item_gift_number, R.id.tv_number, giftNumber));//里面参数是上下文,布局,布局里面的id,数据
//价格下拉列表
spinnerNumber.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int position, long l) {
for (int i1 = 0; i1 < giftNumber.length; i1++) {
mNumber = CastUtil.parseInt(giftNumber[position]);
}
}
@Override
public void onNothingSelected(AdapterView<?> adapterView) {
}
});
3.item_gift_number布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tool="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto">
<com.github.widget.SuperTextView
android:id="@+id/tv_number"//ID是这里
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textSize="14sp"
android:textColor="#333333"
android:paddingTop="8dp"
android:paddingBottom="8dp"
android:paddingStart="10dp"
android:paddingEnd="10dp"
android:gravity="center"
tool:text="87"
app:strokeColor="@color/colorAccent"
app:strokeWidth="1dp"/>
</LinearLayout>
4.下拉列表布局
<androidx.appcompat.widget.AppCompatSpinner
android:id="@+id/spinner_number"
android:layout_width="76dp"
android:layout_height="36dp"
android:layout_marginStart="12dp"
android:layout_marginTop="12dp"
android:layout_marginBottom="12dp"
android:background="@color/white"
tool:text="soidf" />