聲明的方式定義片段我有一個相當複雜的XML的5個獨特的網頁。我想把5頁放在ViewPager中。我可以找到的所有樣本都通過代碼簡單地在每個頁面中放置相同的內容。我想聲明性地在viewpager中定義xml,如下面粘貼的xml。但是這不起作用 - 應用程序停止這個XML。內ViewPager
如果我不能以聲明方式定義它,那麼我可以加載單獨的XML頁面進入viewpager?我找不到這樣做的例子。 感謝, 加里·布萊克利
<?xml version="1.0" encoding="utf-8"?>
<fragment >
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ImageView android:layout_width="match_parent"
android:layout_height="match_parent" android:id="@+id/imageView1"
android:src="@drawable/flashright" android:adjustViewBounds="true" android:scaleType="fitXY">
</ImageView>
</LinearLayout>
</fragment>
<fragment >
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ImageView android:layout_width="match_parent"
android:layout_height="match_parent" android:id="@+id/imageView1"
android:src="@drawable/flashleft" android:adjustViewBounds="true" android:scaleType="fitXY">
</ImageView>
</LinearLayout>
</fragment>
這是一個糟糕的代碼粘貼工作 - 該XML是一個viewpager內。我結束了代碼中的各種XML文件的膨脹。我是Android新手,習慣於XAML,我們可以通過聲明來做任何事情。 – 2012-08-17 19:54:20