@@ -38,6 +38,7 @@ public class AutoCompletionView extends FrameLayout {
3838 private ArrayList <Words > mExtraItems = new ArrayList <>();
3939 private boolean mIsExtended ;
4040 private Delegate mDelegate ;
41+ private List <Words > mItems ;
4142
4243 public interface Delegate {
4344 void onAutoCompletionItemClick (Words aItem );
@@ -77,7 +78,7 @@ private void initialize(Context aContext) {
7778 });
7879 mMinKeyWidth = WidgetPlacement .pixelDimension (getContext (), R .dimen .autocompletion_widget_min_item_width );
7980 mKeyHeight = WidgetPlacement .pixelDimension (getContext (), R .dimen .autocompletion_widget_item_height );
80- mLineWidth = WidgetPlacement . pixelDimension ( getContext (), R . dimen . autocompletion_widget_line_width );
81+ mLineWidth = getMeasuredWidth ( );
8182 mLineHeight = WidgetPlacement .pixelDimension (getContext (), R .dimen .autocompletion_widget_line_height );
8283 mItemPadding = WidgetPlacement .pixelDimension (getContext (), R .dimen .autocompletion_widget_item_padding );
8384 mExtendedHeight = mLineHeight * 6 ;
@@ -119,11 +120,34 @@ private LinearLayout createRow() {
119120 return row ;
120121 }
121122
123+ @ Override
124+ protected void onLayout (boolean changed , int left , int top , int right , int bottom ) {
125+ super .onLayout (changed , left , top , right , bottom );
126+ int width = getMeasuredWidth ();
127+ if (mLineWidth != width && width > 0 ) {
128+ mLineWidth = width ;
129+ layoutItems ();
130+ if (mIsExtended ) {
131+ layoutExtendedItems ();
132+ }
133+ }
134+ }
135+
122136 public void setItems (List <Words > aItems ) {
137+ mItems = aItems ;
138+ if (mLineWidth == 0 ) {
139+ mLineWidth = getMeasuredWidth ();
140+ }
141+ if (mLineWidth > 0 ) {
142+ layoutItems ();
143+ }
144+ }
145+
146+ private void layoutItems () {
123147 mFirstLine .removeAllViews ();
124148 mExtraItems .clear ();
125149 mExtendContent .removeAllViews ();
126- if (aItems == null || aItems .size () == 0 ) {
150+ if (mItems == null || mItems .size () == 0 ) {
127151 exitExtend ();
128152 mExtendButton .setVisibility (View .GONE );
129153 mExtendButtonSeparator .setVisibility (View .GONE );
@@ -134,7 +158,7 @@ public void setItems(List<Words> aItems) {
134158 int currentWidth = 0 ;
135159 int extendButtonWidth = mExtendButton .getWidth ();
136160
137- for (Words item : aItems ) {
161+ for (Words item : mItems ) {
138162 UITextButton textBtn = createButton (item , clickHandler );
139163 if (n == 0 ) {
140164 textBtn .setBackground (getContext ().getDrawable (R .drawable .autocompletion_item_background_first ));
0 commit comments