可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
I have layout with child (NOT as root) element RelativeLayout and then i create ViewPager and insert it as child of my Relative layout, so it's like
+Relative Layout (root)
|
+-- Relative Layout (child)
|
+-- -- ViewPager
For now moment - all ok.
But then i try add some view item to ViewPager with own layout then i got error
10-12 15:32:46.777: E/AndroidRuntime(6031): FATAL EXCEPTION: main 10-12 15:32:46.777: E/AndroidRuntime(6031): java.lang.StackOverflowError 10-12 15:32:46.777: E/AndroidRuntime(6031): at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5035)
How do that ViewPager will me as Child of RelativeLayout with havin own Child Views?
回答1:
Problem solved!
it's happened because i call LayoutInflater.inflate([subViewOfViewPager],[ParentOfViewPager])
need
change to LayoutInflater.inflate([subViewOfViewPager],null)
More words:
It's happened because when called inflate with second parameter, view inserting as subchild of given ViewGroup, and then i try add this View to ViewPager. View can have only one Parent ViewGroup element.
回答2:
Simplified version of answer
@Nullable @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View view = inflater.inflate(R.layout.cab_listing, container,false); return view; }