@@ -35,62 +35,70 @@ public ItemsView getBodyView() {
3535
3636 @ Override
3737 public void buildBodyView () {
38+ mParams .dialogParams .absoluteWidth = LinearLayout .LayoutParams .WRAP_CONTENT ;
39+
40+ final PopupParams popupParams = mParams .popupParams ;
41+ final int arrowDirection = popupParams .arrowDirection ;
42+
3843 LinearLayout rootLinearLayout = buildLinearLayout ();
44+ //箭头在左右情况,布局改为水平
45+ if (arrowDirection == PopupParams .DIRECTION_LEFT || arrowDirection == PopupParams .DIRECTION_RIGHT ) {
46+ rootLinearLayout .setOrientation (LinearLayout .HORIZONTAL );
47+ }
3948 mRoot = rootLinearLayout ;
40- if (mItemsView == null ) {
41- mParams .dialogParams .absoluteWidth = LinearLayout .LayoutParams .WRAP_CONTENT ;
4249
43- final PopupParams popupParams = mParams .popupParams ;
44- final View arrowView = new View (mContext );
45- mRoot .addView (arrowView );
50+ final View arrowView = new View (mContext );
51+ int backgroundColor = popupParams .backgroundColor != 0
52+ ? popupParams .backgroundColor : mParams .dialogParams .backgroundColor ;
53+ Drawable arrowDrawable = new TriangleArrowDrawable (arrowDirection , backgroundColor );
54+ if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .JELLY_BEAN ) {
55+ arrowView .setBackground (arrowDrawable );
56+ } else {
57+ arrowView .setBackgroundDrawable (arrowDrawable );
58+ }
4659
47- final int arrowDirection = popupParams .arrowDirection ;
48- int backgroundColor = popupParams .backgroundColor != 0
49- ? popupParams .backgroundColor : mParams .dialogParams .backgroundColor ;
50- Drawable arrowDrawable = new TriangleArrowDrawable (arrowDirection , backgroundColor );
51- if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .JELLY_BEAN ) {
52- arrowView .setBackground (arrowDrawable );
53- } else {
54- arrowView .setBackgroundDrawable (arrowDrawable );
55- }
60+ CardView cardView = buildCardView ();
61+ mItemsView = new BodyRecyclerView (mContext , mParams .popupParams
62+ , mParams .dialogParams , mParams .rvItemListener );
63+ final View itemsViewView = mItemsView .getView ();
64+ cardView .addView (itemsViewView );
5665
57- CardView cardView = buildCardView ();
66+ if (arrowDirection == PopupParams .DIRECTION_LEFT
67+ || arrowDirection == PopupParams .DIRECTION_TOP ) {
68+ mRoot .addView (arrowView );
5869 mRoot .addView (cardView );
70+ } else {
71+ mRoot .addView (cardView );
72+ mRoot .addView (arrowView );
73+ }
5974
60- mItemsView = new BodyRecyclerView (mContext , mParams .popupParams
61- , mParams .dialogParams , mParams .rvItemListener );
62- final View itemsViewView = mItemsView .getView ();
63- cardView .addView (itemsViewView );
64-
65- itemsViewView .addOnLayoutChangeListener (new View .OnLayoutChangeListener () {
66- @ Override
67- public void onLayoutChange (View v , int left , int top , int right , int bottom
68- , int oldLeft , int oldTop , int oldRight , int oldBottom ) {
69- mParams .dialogParams .absoluteWidth = v .getWidth ();
70- int arrowViewWidth = (int ) (v .getWidth () * ARROW_WEIGHT );
71- LayoutParams arrowViewLayoutParams = (LayoutParams ) arrowView .getLayoutParams ();
72- if (arrowViewLayoutParams == null ) {
73- arrowViewLayoutParams = new LayoutParams (arrowViewWidth , arrowViewWidth );
75+ mRoot .addOnLayoutChangeListener (new View .OnLayoutChangeListener () {
76+ @ Override
77+ public void onLayoutChange (View v , int left , int top , int right , int bottom
78+ , int oldLeft , int oldTop , int oldRight , int oldBottom ) {
79+ mParams .dialogParams .absoluteWidth = itemsViewView .getWidth ();
80+ int arrowViewWidth = (int ) (itemsViewView .getWidth () * ARROW_WEIGHT );
81+ LayoutParams arrowViewLayoutParams = (LayoutParams ) arrowView .getLayoutParams ();
82+ if (arrowViewLayoutParams == null ) {
83+ arrowViewLayoutParams = new LayoutParams (arrowViewWidth , arrowViewWidth );
84+ } else {
85+ arrowViewLayoutParams .width = arrowViewWidth ;
86+ arrowViewLayoutParams .height = arrowViewWidth ;
87+ }
88+ if (bottom != 0 && oldBottom != 0
89+ && bottom == oldBottom ) {
90+ if (popupParams .arrowGravity == PopupParams .GRAVITY_CENTER ) {
91+ arrowViewLayoutParams .leftMargin = (mParams .dialogParams .absoluteWidth / 2 ) - (arrowViewWidth / 2 );
92+ } else if (popupParams .arrowGravity == PopupParams .GRAVITY_RIGHT ) {
93+ arrowViewLayoutParams .leftMargin = (int ) (mParams .dialogParams .absoluteWidth * (1 - ARROW_WEIGHT )) - arrowViewWidth ;
7494 } else {
75- arrowViewLayoutParams .width = arrowViewWidth ;
76- arrowViewLayoutParams .height = arrowViewWidth ;
95+ arrowViewLayoutParams .leftMargin = arrowViewWidth ;
7796 }
78- if ((bottom != 0 && oldBottom != 0 && bottom == oldBottom )
79- || (top != 0 && oldTop != 0 && top == oldTop )) {
80- switch (arrowDirection ) {
81- case PopupParams .DIRECTION_TOP :
82- if (popupParams .arrowGravity == PopupParams .GRAVITY_RIGHT ) {
83- int offset = arrowViewWidth / 2 ;
84- arrowViewLayoutParams .leftMargin = (int ) (mParams .dialogParams .absoluteWidth * (1 - ARROW_WEIGHT )) - offset ;
85- }
86- break ;
87- }
88- itemsViewView .removeOnLayoutChangeListener (this );
89- }
90- arrowView .setLayoutParams (arrowViewLayoutParams );
97+ itemsViewView .removeOnLayoutChangeListener (this );
9198 }
92- });
93- }
99+ arrowView .setLayoutParams (arrowViewLayoutParams );
100+ }
101+ });
94102 }
95103
96104 @ Override
0 commit comments