|
36 | 36 | import android.view.View;
|
37 | 37 | import android.view.ViewGroup;
|
38 | 38 | import android.view.ViewParent;
|
| 39 | +import android.view.WindowManager; |
39 | 40 | import android.view.accessibility.AccessibilityEvent;
|
40 | 41 | import android.view.accessibility.AccessibilityNodeInfo;
|
41 | 42 | import android.widget.HorizontalScrollView;
|
@@ -179,6 +180,7 @@ public interface OnTabSelectedListener {
|
179 | 180 | private int mTabMaxWidth = Integer.MAX_VALUE;
|
180 | 181 | private final int mRequestedTabMinWidth;
|
181 | 182 | private final int mRequestedTabMaxWidth;
|
| 183 | + private int xTabDisplayNum; |
182 | 184 | private final int mScrollableTabMinWidth;
|
183 | 185 |
|
184 | 186 | private int mContentInsetStart;
|
@@ -271,6 +273,7 @@ public XTabLayout(Context context, AttributeSet attrs, int defStyleAttr) {
|
271 | 273 | mTabTextColors = createColorStateList(mTabTextColors.getDefaultColor(), selected);
|
272 | 274 | }
|
273 | 275 |
|
| 276 | + xTabDisplayNum = a.getInt(R.styleable.XTabLayout_xTabDisplayNum, 0); |
274 | 277 | mRequestedTabMinWidth = a.getDimensionPixelSize(R.styleable.XTabLayout_xTabMinWidth,
|
275 | 278 | INVALID_WIDTH);
|
276 | 279 | mRequestedTabMaxWidth = a.getDimensionPixelSize(R.styleable.XTabLayout_xTabMaxWidth,
|
@@ -310,6 +313,10 @@ public void setSelectedTabIndicatorHeight(int height) {
|
310 | 313 | mTabStrip.setSelectedIndicatorHeight(height);
|
311 | 314 | }
|
312 | 315 |
|
| 316 | + public void setxTabDisplayNum(int xTabDisplayNum) { |
| 317 | + this.xTabDisplayNum = xTabDisplayNum; |
| 318 | + } |
| 319 | + |
313 | 320 | /**
|
314 | 321 | * Set the scroll position of the tabs. This is useful for when the tabs are being displayed as
|
315 | 322 | * part of a scrolling container such as {@link ViewPager}.
|
@@ -346,7 +353,7 @@ private void setScrollPosition(int position, float positionOffset, boolean updat
|
346 | 353 | if (updateSelectedText) {
|
347 | 354 | setSelectedTabView(roundedPosition);
|
348 | 355 | }
|
349 |
| - Log.w("AAA","end"); |
| 356 | + Log.w("AAA", "end"); |
350 | 357 | }
|
351 | 358 |
|
352 | 359 |
|
@@ -713,6 +720,7 @@ private void populateFromPagerAdapter() {
|
713 | 720 |
|
714 | 721 | if (mPagerAdapter != null) {
|
715 | 722 | final int adapterCount = mPagerAdapter.getCount();
|
| 723 | + |
716 | 724 | for (int i = 0; i < adapterCount; i++) {
|
717 | 725 | addTab(newTab().setText(mPagerAdapter.getPageTitle(i)), false);
|
718 | 726 | }
|
@@ -921,7 +929,7 @@ public void onAnimationUpdate(ValueAnimatorCompat animator) {
|
921 | 929 | }
|
922 | 930 |
|
923 | 931 | // Now animate the indicator
|
924 |
| - Log.w("AAA","123"); |
| 932 | + Log.w("AAA", "123"); |
925 | 933 | mTabStrip.animateIndicatorToPosition(newPosition, ANIMATION_DURATION);
|
926 | 934 | }
|
927 | 935 |
|
@@ -1781,7 +1789,7 @@ private void setIndicatorPosition(int left, int right) {
|
1781 | 1789 | }
|
1782 | 1790 |
|
1783 | 1791 | void animateIndicatorToPosition(final int position, int duration) {
|
1784 |
| - Log.w("AAA","animateIndicatorToPosition"); |
| 1792 | + Log.w("AAA", "animateIndicatorToPosition"); |
1785 | 1793 | if (mIndicatorAnimator != null && mIndicatorAnimator.isRunning()) {
|
1786 | 1794 | mIndicatorAnimator.cancel();
|
1787 | 1795 | }
|
@@ -1901,6 +1909,20 @@ private int getDefaultHeight() {
|
1901 | 1909 | }
|
1902 | 1910 |
|
1903 | 1911 | private int getTabMinWidth() {
|
| 1912 | + Log.w("AAA","getTabMinWidth 1111"); |
| 1913 | + if (mPagerAdapter != null && xTabDisplayNum != 0) { |
| 1914 | + WindowManager wm = (WindowManager) getContext() |
| 1915 | + .getSystemService(Context.WINDOW_SERVICE); |
| 1916 | + if(mPagerAdapter.getCount()<xTabDisplayNum){ |
| 1917 | + |
| 1918 | + Log.w("AAA","getTabMinWidth 22222"); |
| 1919 | + return wm.getDefaultDisplay().getWidth()/mPagerAdapter.getCount(); |
| 1920 | + }else{ |
| 1921 | + Log.w("AAA","getTabMinWidth 33333"); |
| 1922 | + return wm.getDefaultDisplay().getWidth()/xTabDisplayNum; |
| 1923 | + } |
| 1924 | + } |
| 1925 | + Log.w("AAA","getTabMinWidth 44444"); |
1904 | 1926 | if (mRequestedTabMinWidth != INVALID_WIDTH) {
|
1905 | 1927 | // If we have been given a min width, use it
|
1906 | 1928 | return mRequestedTabMinWidth;
|
|
0 commit comments