【发布时间】:2012-04-02 05:20:41
【问题描述】:
我正在尝试设置具有多个布局的 ViewPager,每个布局中有 2 个 TextView。当我运行我的应用程序时,我无法让我的 TextViews 正确显示。我的寻呼机工作正常,但它没有显示我在 XML 布局中的 Textviews。
这是我的 PageAdapter 中的代码
public class MyPageAdapter extends PagerAdapter {
public int getCount() {
return 31;
}
public Object instantiateItem(View collection, int position) {
LayoutInflater inflater = (LayoutInflater) collection.getContext()
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
int resId = 0;
switch (position) {
case 0:
resId = R.layout.main_menu;
break;
case 1:
resId = R.layout.article1;
break;
case 2:
resId = R.layout.article2;
break;
....
....
View view = inflater.inflate(resId, null);
((ViewPager) collection).addView(view, 0);
return view;
这就是我的 XML
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" android:background="@drawable/background" android:clickable="true"
android:id="@+id/layout13"
android:weightSum="0">
<TextView
android:id="@+id/textView01"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical|center_horizontal"
android:padding="12dp"
android:text="@string/article13"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#000000" />
<TextView
android:id="@+id/textView02"
android:layout_width="match_parent"
android:layout_height="302dp"
android:gravity="center_vertical|center_horizontal"
android:text="@string/body13"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#000000" />
<android.support.v4.view.ViewPager
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@id/viewPager" >
</android.support.v4.view.ViewPager>
</LinearLayout>
我尝试在我的 XML 布局中移动到我的 LinearLayout 的正下方,我得到了全屏,但我的所有文本都消失了。这可能是我缺少的一些简单的东西,但任何对此的帮助将不胜感激!
【问题讨论】:
-
你能解释清楚吗...
标签: android android-layout android-viewpager