Вам нужно установить высоту в представлении пейджера, а не в xml.
import android.content.Context;
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;
import android.view.View;
public class CustomViewPager extends ViewPager {
public CustomViewPager(Context context) {
super(context);
}
public CustomViewPager(Context context, AttributeSet attrs){
super(context, attrs);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, 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);
}
}
Игра вокруг с помощью метода onMeasure получите, что вам нужно, то ViewPager контролирует высоту + ширина ее детей
Если это не работает, вы можете overide методы getPageHeight и GetPagewidth из Просмотр пейджера
@Override
public float getPageHeight(int position) {
//Return different height based on position.
// Height is returned as a float
if(position == 1)
{
return (0.35f);
}
else{
retrun 0.50f;
}
}
будет ли вы вывести номер ур кода? – Android
Я не тонкий код поможет, это простой ViewPager с некоторым фрагментом с разной высотой. – frenk91
Попробуйте установить высоту в match_parent. –