我尝试两次包含以下布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<com.viewpagerindicator.TabPageIndicator
android:id="@+id/indicator"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
喜欢下面的
<include
android:id="@+id/include1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
layout="@layout/view_pager" />
<include
android:id="@+id/include2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
layout="@layout/view_pager" />
实际上,如果我那样做,第二个 View 寻呼机将无法工作...指标 2) 一切正常。有更好的方法吗?复制布局来实现这一点似乎使包含对同一布局的多个包含无用....
我认为我得到的引用是正确的,但是如果我包含相同的布局它就不起作用......
pager1= (ViewPager)(findViewById(R.id.include1).findViewById(R.id.pager));
pager2= (ViewPager)(findViewById(R.id.include2).findViewById(R.id.pager));
如果我复制布局,一切都会完美...
编辑:
我认为这与 FragmentManager 有关,因为 View 寻呼机具有相同的 id...但我不知道如何正确解决...
最佳答案
是的,这是可以做到的。您可以多次膨胀布局,但必须以编程方式进行包含。查看answer同样的问题。
关于android - xml - 多次包含相同的布局不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17171817/