-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
“xiaohaibin
committed
Mar 12, 2019
1 parent
9077ad7
commit 8f441f3
Showing
3 changed files
with
46 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
pagemenulibrary/src/main/java/com/stx/xhb/pagemenulibrary/CustomViewPager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.stx.xhb.pagemenulibrary; | ||
|
||
import android.content.Context; | ||
import android.support.annotation.NonNull; | ||
import android.support.annotation.Nullable; | ||
import android.support.v4.view.ViewPager; | ||
import android.util.AttributeSet; | ||
import android.view.View; | ||
|
||
/** | ||
* @author: xiaohaibin. | ||
* @time: 2019/3/12 | ||
* @mail:[email protected] | ||
* @github:https://github.com/xiaohaibin | ||
* @describe: 自定义viewpager,自适应高度 | ||
*/ | ||
public class CustomViewPager extends ViewPager { | ||
|
||
public CustomViewPager(@NonNull Context context) { | ||
super(context); | ||
} | ||
|
||
public CustomViewPager(@NonNull Context context, @Nullable AttributeSet attrs) { | ||
super(context, attrs); | ||
} | ||
|
||
@Override | ||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { | ||
int height = 0; | ||
for (int i = 0; i < getChildCount(); i++) { | ||
View child = getChildAt(i); | ||
child.measure(widthMeasureSpec, | ||
MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED)); | ||
int h = child.getMeasuredHeight(); | ||
if (h > height) { | ||
height = h; | ||
} | ||
} | ||
heightMeasureSpec = MeasureSpec.makeMeasureSpec(height, | ||
MeasureSpec.EXACTLY); | ||
super.onMeasure(widthMeasureSpec, heightMeasureSpec); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters