|
2 | 2 |
|
3 | 3 | import android.content.Context;
|
4 | 4 | import android.support.annotation.NonNull;
|
| 5 | +import android.support.v7.widget.LinearLayoutManager; |
| 6 | +import android.support.v7.widget.RecyclerView; |
5 | 7 | import android.util.Log;
|
6 | 8 | import android.view.View;
|
7 | 9 | import android.widget.AdapterView;
|
8 | 10 | import android.widget.ArrayAdapter;
|
9 | 11 | import android.widget.Spinner;
|
10 | 12 | import android.widget.TextView;
|
11 | 13 |
|
| 14 | +import com.lxj.easyadapter.CommonAdapter; |
| 15 | +import com.lxj.easyadapter.ViewHolder; |
12 | 16 | import com.lxj.xpopup.XPopup;
|
13 | 17 | import com.lxj.xpopup.animator.PopupAnimator;
|
| 18 | +import com.lxj.xpopup.core.BottomPopupView; |
14 | 19 | import com.lxj.xpopup.core.CenterPopupView;
|
15 | 20 | import com.lxj.xpopup.enums.PopupAnimation;
|
16 | 21 | import com.lxj.xpopup.util.XPopupUtils;
|
17 | 22 | import com.lxj.xpopupdemo.R;
|
18 | 23 |
|
| 24 | +import java.util.ArrayList; |
| 25 | + |
19 | 26 | /**
|
20 | 27 | * Description:
|
21 | 28 | * Create by dance, at 2018/12/9
|
@@ -44,8 +51,8 @@ public void onItemSelected(AdapterView<?> parent, View view, final int position,
|
44 | 51 | @Override
|
45 | 52 | public void run() {
|
46 | 53 | XPopup.get(getContext())
|
47 |
| - .popupAnimation(datas[position]) |
48 |
| - .asCustom(new CustomPopup(getContext())) |
| 54 | +// .popupAnimation(datas[position]) |
| 55 | + .asCustom(new CustomPopup2(getContext())) |
49 | 56 | // .setWidthAndHeight(XPopupUtils.getWindowWidth(getContext()),XPopupUtils.getWindowHeight(getContext()))
|
50 | 57 | .show();
|
51 | 58 | }
|
@@ -88,6 +95,46 @@ public void onClick(View v) {
|
88 | 95 | // @Override
|
89 | 96 | // protected int getMaxWidth() {
|
90 | 97 | // return 1200;
|
| 98 | +// } |
| 99 | + } |
| 100 | + |
| 101 | + static class CustomPopup2 extends BottomPopupView { |
| 102 | + RecyclerView recyclerView; |
| 103 | + public CustomPopup2(@NonNull Context context) { |
| 104 | + super(context); |
| 105 | + } |
| 106 | + |
| 107 | + @Override |
| 108 | + protected int getImplLayoutId() { |
| 109 | + return R.layout.custom_popup2; |
| 110 | + } |
| 111 | + @Override |
| 112 | + protected void initPopupContent() { |
| 113 | + super.initPopupContent(); |
| 114 | + recyclerView = findViewById(R.id.recyclerView); |
| 115 | + recyclerView.setLayoutManager(new LinearLayoutManager(getContext())); |
| 116 | + ArrayList<String> data = new ArrayList<>(); |
| 117 | + for (int i = 0; i < 3; i++) { |
| 118 | + data.add(""+i); |
| 119 | + } |
| 120 | + |
| 121 | + recyclerView.setAdapter(new CommonAdapter<String>(android.R.layout.simple_list_item_1, data) { |
| 122 | + @Override |
| 123 | + protected void convert(@NonNull ViewHolder holder, @NonNull String s, int position) { |
| 124 | + holder.setText(android.R.id.text1, s); |
| 125 | + } |
| 126 | + }); |
| 127 | + } |
| 128 | + |
| 129 | +// @Override |
| 130 | +// protected int getMaxHeight() { |
| 131 | +// return 1200; |
| 132 | +// } |
| 133 | +// |
| 134 | + //返回0表示让宽度撑满window,或者你可以返回一个任意宽度 |
| 135 | +// @Override |
| 136 | +// protected int getMaxWidth() { |
| 137 | +// return 1200; |
91 | 138 | // }
|
92 | 139 | }
|
93 | 140 | }
|
0 commit comments