Ich dachte, was ich wäre ziemlich einfach wollte, aber es muss etwas fehlt mir ...Benutzerdefinierte Layout Mit Android ViewPager
ich ein Setup ViewPager ohne Probleme. Es gleitet horizontal zwischen verschiedenen Fragmenten. Wenn ich jedoch versuche, einen Header (oder etwas anderes) zu meinem Layout hinzuzufügen, wird erzwungen. Wie mache ich das? Hier
ist das XML-Layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/background_light"
android:padding="0dp">
<!-- ***** HEADER ***** -->
<RelativeLayout android:id="@+id/header"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:layout_marginTop="0dp"
android:background="@drawable/background_dark"
android:padding="0dp">
<ImageView android:id="@+id/logo"
android:contentDescription="@string/logo_contentDescription"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentBottom="true"
android:layout_marginLeft="5sp"
android:src="@drawable/logo" />
</RelativeLayout>
<!-- ***** SLIDER ***** -->
<android.support.v4.view.ViewPager
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/main_pager_view">
<android.support.v4.view.PagerTitleStrip
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:layout_weight="1" />
</android.support.v4.view.ViewPager>
</LinearLayout>
Hier ist meine logcat:
03-28 19:31:30.447: D/dalvikvm(1023): GC_FOR_ALLOC freed 40K, 3% free 9068K/9347K, paused 74ms
03-28 19:31:30.646: I/dalvikvm-heap(1023): Grow heap (frag case) to 25.721MB for 17613052-byte allocation
03-28 19:31:30.844: D/dalvikvm(1023): GC_CONCURRENT freed <1K, 2% free 26267K/26567K, paused 20ms+19ms
03-28 19:31:33.524: D/dalvikvm(1023): GC_FOR_ALLOC freed 0K, 2% free 26267K/26567K, paused 45ms
03-28 19:31:33.524: I/dalvikvm-heap(1023): Forcing collection of SoftReferences for 39642008-byte allocation
03-28 19:31:33.604: D/dalvikvm(1023): GC_BEFORE_OOM freed 9K, 2% free 26258K/26567K, paused 81ms
03-28 19:31:33.604: E/dalvikvm-heap(1023): Out of memory on a 39642008-byte allocation.
03-28 19:31:33.614: I/dalvikvm(1023): "main" prio=5 tid=1 RUNNABLE
03-28 19:31:33.614: I/dalvikvm(1023): | group="main" sCount=0 dsCount=0 obj=0x409c1460 self=0x12810
03-28 19:31:33.614: I/dalvikvm(1023): | sysTid=1023 nice=0 sched=0/0 cgrp=default handle=1074082952
03-28 19:31:33.614: I/dalvikvm(1023): | schedstat=(3201691068 885739274 101) utm=284 stm=36 core=0
03-28 19:31:33.614: I/dalvikvm(1023): at android.graphics.Bitmap.nativeCreate(Native Method)
03-28 19:31:33.624: I/dalvikvm(1023): at android.graphics.Bitmap.createBitmap(Bitmap.java:605)
03-28 19:31:33.624: I/dalvikvm(1023): at android.graphics.Bitmap.createBitmap(Bitmap.java:551)
03-28 19:31:33.624: I/dalvikvm(1023): at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:437)
03-28 19:31:33.624: I/dalvikvm(1023): at android.graphics.BitmapFactory.finishDecode(BitmapFactory.java:524)
03-28 19:31:33.624: I/dalvikvm(1023): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:499)
03-28 19:31:33.624: I/dalvikvm(1023): at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:351)
03-28 19:31:33.624: I/dalvikvm(1023): at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:773)
03-28 19:31:33.624: I/dalvikvm(1023): at android.content.res.Resources.loadDrawable(Resources.java:1937)
03-28 19:31:33.624: I/dalvikvm(1023): at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
03-28 19:31:33.624: I/dalvikvm(1023): at android.view.View.<init>(View.java:2785)
03-28 19:31:33.624: I/dalvikvm(1023): at android.view.ViewGroup.<init>(ViewGroup.java:385)
03-28 19:31:33.624: I/dalvikvm(1023): at android.widget.LinearLayout.<init>(LinearLayout.java:174)
03-28 19:31:33.634: I/dalvikvm(1023): at android.widget.LinearLayout.<init>(LinearLayout.java:170)
03-28 19:31:33.634: I/dalvikvm(1023): at java.lang.reflect.Constructor.constructNative(Native Method)
03-28 19:31:33.634: I/dalvikvm(1023): at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
03-28 19:31:33.634: I/dalvikvm(1023): at android.view.LayoutInflater.createView(LayoutInflater.java:586)
03-28 19:31:33.634: I/dalvikvm(1023): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
03-28 19:31:33.634: I/dalvikvm(1023): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:653)
03-28 19:31:33.645: I/dalvikvm(1023): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:678)
03-28 19:31:33.645: I/dalvikvm(1023): at android.view.LayoutInflater.inflate(LayoutInflater.java:466)
03-28 19:31:33.645: I/dalvikvm(1023): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
03-28 19:31:33.645: I/dalvikvm(1023): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
03-28 19:31:33.645: I/dalvikvm(1023): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:251)
03-28 19:31:33.645: I/dalvikvm(1023): at android.app.Activity.setContentView(Activity.java:1835)
03-28 19:31:33.645: I/dalvikvm(1023): at com.mojackllc.postr.MainPagerActivity.onCreate(MainPagerActivity.java:20)
03-28 19:31:33.645: I/dalvikvm(1023): at android.app.Activity.performCreate(Activity.java:4465)
03-28 19:31:33.645: I/dalvikvm(1023): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
03-28 19:31:33.645: I/dalvikvm(1023): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
03-28 19:31:33.645: I/dalvikvm(1023): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
03-28 19:31:33.645: I/dalvikvm(1023): at android.app.ActivityThread.access$600(ActivityThread.java:123)
03-28 19:31:33.645: I/dalvikvm(1023): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
03-28 19:31:33.645: I/dalvikvm(1023): at android.os.Handler.dispatchMessage(Handler.java:99)
03-28 19:31:33.645: I/dalvikvm(1023): at android.os.Looper.loop(Looper.java:137)
03-28 19:31:33.645: I/dalvikvm(1023): at android.app.ActivityThread.main(ActivityThread.java:4424)
03-28 19:31:33.645: I/dalvikvm(1023): at java.lang.reflect.Method.invokeNative(Native Method)
03-28 19:31:33.645: I/dalvikvm(1023): at java.lang.reflect.Method.invoke(Method.java:511)
03-28 19:31:33.645: I/dalvikvm(1023): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
03-28 19:31:33.645: I/dalvikvm(1023): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
03-28 19:31:33.645: I/dalvikvm(1023): at dalvik.system.NativeStart.main(Native Method)
03-28 19:31:33.654: D/AndroidRuntime(1023): Shutting down VM
03-28 19:31:33.654: W/dalvikvm(1023): threadid=1: thread exiting with uncaught exception (group=0x409c01f8)
03-28 19:31:33.754: E/AndroidRuntime(1023): FATAL EXCEPTION: main
03-28 19:31:33.754: E/AndroidRuntime(1023): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mojackllc.postr/com.mojackllc.postr.MainPagerActivity}: android.view.InflateException: Binary XML file line #2: Error inflating class <unknown>
03-28 19:31:33.754: E/AndroidRuntime(1023): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
03-28 19:31:33.754: E/AndroidRuntime(1023): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
03-28 19:31:33.754: E/AndroidRuntime(1023): at android.app.ActivityThread.access$600(ActivityThread.java:123)
03-28 19:31:33.754: E/AndroidRuntime(1023): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
03-28 19:31:33.754: E/AndroidRuntime(1023): at android.os.Handler.dispatchMessage(Handler.java:99)
03-28 19:31:33.754: E/AndroidRuntime(1023): at android.os.Looper.loop(Looper.java:137)
03-28 19:31:33.754: E/AndroidRuntime(1023): at android.app.ActivityThread.main(ActivityThread.java:4424)
03-28 19:31:33.754: E/AndroidRuntime(1023): at java.lang.reflect.Method.invokeNative(Native Method)
03-28 19:31:33.754: E/AndroidRuntime(1023): at java.lang.reflect.Method.invoke(Method.java:511)
03-28 19:31:33.754: E/AndroidRuntime(1023): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
03-28 19:31:33.754: E/AndroidRuntime(1023): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
03-28 19:31:33.754: E/AndroidRuntime(1023): at dalvik.system.NativeStart.main(Native Method)
03-28 19:31:33.754: E/AndroidRuntime(1023): Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class <unknown>
03-28 19:31:33.754: E/AndroidRuntime(1023): at android.view.LayoutInflater.createView(LayoutInflater.java:606)
03-28 19:31:33.754: E/AndroidRuntime(1023): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
03-28 19:31:33.754: E/AndroidRuntime(1023): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:653)
03-28 19:31:33.754: E/AndroidRuntime(1023): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:678)
03-28 19:31:33.754: E/AndroidRuntime(1023): at android.view.LayoutInflater.inflate(LayoutInflater.java:466)
03-28 19:31:33.754: E/AndroidRuntime(1023): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
03-28 19:31:33.754: E/AndroidRuntime(1023): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
03-28 19:31:33.754: E/AndroidRuntime(1023): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:251)
03-28 19:31:33.754: E/AndroidRuntime(1023): at android.app.Activity.setContentView(Activity.java:1835)
03-28 19:31:33.754: E/AndroidRuntime(1023): at com.mojackllc.postr.MainPagerActivity.onCreate(MainPagerActivity.java:20)
03-28 19:31:33.754: E/AndroidRuntime(1023): at android.app.Activity.performCreate(Activity.java:4465)
03-28 19:31:33.754: E/AndroidRuntime(1023): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
03-28 19:31:33.754: E/AndroidRuntime(1023): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
03-28 19:31:33.754: E/AndroidRuntime(1023): ... 11 more
03-28 19:31:33.754: E/AndroidRuntime(1023): Caused by: java.lang.reflect.InvocationTargetException
03-28 19:31:33.754: E/AndroidRuntime(1023): at java.lang.reflect.Constructor.constructNative(Native Method)
03-28 19:31:33.754: E/AndroidRuntime(1023): at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
03-28 19:31:33.754: E/AndroidRuntime(1023): at android.view.LayoutInflater.createView(LayoutInflater.java:586)
03-28 19:31:33.754: E/AndroidRuntime(1023): ... 23 more
03-28 19:31:33.754: E/AndroidRuntime(1023): Caused by: java.lang.OutOfMemoryError
03-28 19:31:33.754: E/AndroidRuntime(1023): at android.graphics.Bitmap.nativeCreate(Native Method)
03-28 19:31:33.754: E/AndroidRuntime(1023): at android.graphics.Bitmap.createBitmap(Bitmap.java:605)
03-28 19:31:33.754: E/AndroidRuntime(1023): at android.graphics.Bitmap.createBitmap(Bitmap.java:551)
03-28 19:31:33.754: E/AndroidRuntime(1023): at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:437)
03-28 19:31:33.754: E/AndroidRuntime(1023): at android.graphics.BitmapFactory.finishDecode(BitmapFactory.java:524)
03-28 19:31:33.754: E/AndroidRuntime(1023): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:499)
03-28 19:31:33.754: E/AndroidRuntime(1023): at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:351)
03-28 19:31:33.754: E/AndroidRuntime(1023): at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:773)
03-28 19:31:33.754: E/AndroidRuntime(1023): at android.content.res.Resources.loadDrawable(Resources.java:1937)
03-28 19:31:33.754: E/AndroidRuntime(1023): at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
03-28 19:31:33.754: E/AndroidRuntime(1023): at android.view.View.<init>(View.java:2785)
03-28 19:31:33.754: E/AndroidRuntime(1023): at android.view.ViewGroup.<init>(ViewGroup.java:385)
03-28 19:31:33.754: E/AndroidRuntime(1023): at android.widget.LinearLayout.<init>(LinearLayout.java:174)
03-28 19:31:33.754: E/AndroidRuntime(1023): at android.widget.LinearLayout.<init>(LinearLayout.java:170)
03-28 19:31:33.754: E/AndroidRuntime(1023): ... 26 more
Können Sie den Logcat-Fehler posten, den Sie erhalten? Außerdem sollten Sie beim Bereitstellen von Layoutgrößen dp oder dip verwenden. SP sollte bei der Festlegung der Schriftgrößen verwendet werden. – dymmeh
Logcat veröffentlicht! Ich ändere auch sp -> dp. – Jabari
Sie haben eins verpasst: P Sie müssen keinen Wert angeben, wenn Sie nur den Wert 0dip möchten. Ex. android: padding = "0dp" wenn du willst, dass es 0 ist, füge das android: padding-Attribut nicht zu diesem Element hinzu. Die Einstellung auf 0 ist völlig in Ordnung. Aber wenn man es überhaupt nicht hat, reduziert es den Code und räumt die Dinge etwas auf. Nur ein Tipp, der nützlich sein könnte :) – dymmeh