Ich versuche, einen ViewPager mit einer Anzahl von Layouts mit 2 TextViews in jedem Layout einzurichten. Ich habe Probleme, meine TextViews korrekt anzuzeigen, wenn ich meine App starte. Mein Pager funktioniert gut, aber die Textansichten, die ich in meinem XML-Layout habe, werden nicht angezeigt.Android ViewPager Anzeigen von TextView in Layout
Hier ist mein Code, den ich in meinem Pageadapter haben
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;
Dies ist, was ich für meine 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>
Ich habe versucht, Verschieben des um in meinem XML-Layout nach rechts unten haben Mein LinearLayout und ich bekomme den ganzen Bildschirm, aber alle meine Texte verschwinden. Es ist wahrscheinlich etwas Einfaches, das ich vermisse, aber jede Hilfe dazu würde sehr geschätzt werden!
können Sie es eindeutig erklären ... –