The problem is that the "wrap_content" doesn't seem to be working with the View pager.
Here is the solution:
http://stackoverflow.com/questions/8394681/android-i-am-unable-to-have-viewpager-wrap-content
That's it, don't hesitate to comment, to share your knowledge and to correct me.
Here is the solution:
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);
}
}
reference:http://stackoverflow.com/questions/8394681/android-i-am-unable-to-have-viewpager-wrap-content
That's it, don't hesitate to comment, to share your knowledge and to correct me.
Thanks man. It works like a charm!
ReplyDeletesaved my day. lots of thanks, millions of thanks
ReplyDeletelove you man!
ReplyDeletelove you man! 2
ReplyDeletehow about the layout? what i need to do?
ReplyDeleteWorks for me..
ReplyDeleteWorks fine
ReplyDeleteShit doesn't work.
ReplyDeletethanks a lot.. this was a perfect solution for me
ReplyDeleteGreat information you provided.Thank you for sharing
ReplyDeleteIf you are looking for data science training please visit our website
Data science training in btm layout
super blogs...!
ReplyDeleteinternship in chennai for ece students
internships in chennai for cse students 2019
Inplant training in chennai
internship for eee students
free internship in chennai
eee internship in chennai
internship for ece students in chennai
inplant training in bangalore for cse
inplant training in bangalore
ccna training in chennai
goruntulu show
ReplyDeleteücretli
LKR
This is a really smart solution for the ViewPager content wrapping issue! I've struggled with this problem before and your approach with custom ViewPager and measuring children is elegant. Android development has so many of these tricky UI challenges that require creative solutions. The same kind of problem-solving mindset applies to AI development, where you often need to find creative ways to handle complex interactions between components. For developers expanding into AI, understanding these foundational problem-solving skills is essential. I've been looking into Agentic AI weekend classes in Electronic City to balance my learning with work commitments. Weekend classes are perfect for working professionals.
ReplyDelete