我有这个xml,我在那里显示一个CalendarView和一堆按钮。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawerActivity"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.teamtreehouse.oslist.MainActivity4">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<CalendarView
android:id="@+id/calendarView"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tableLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/calendarView"
android:padding="5dp"
android:stretchColumns="0"
android:textAlignment="center">
<TableRow
android:id="@+id/tableRow1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="@+id/trackAttendance"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:background="@drawable/mybuttons"
android:paddingLeft="30dp"
android:paddingRight="30dp"
android:text="Track Class Attendance"
android:textColor="#ffffff"
android:textSize="17dp"></Button>
</TableRow>
<TableRow
android:id="@+id/tableRow2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="@+id/trackSessions"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:background="@drawable/mybuttons"
android:paddingLeft="30dp"
android:paddingRight="30dp"
android:text="Track Study Sessions"
android:textColor="#ffffff"
android:textSize="17dp"></Button>
</TableRow>
<TableRow
android:id="@+id/tableRow3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="@+id/trackActivities"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:background="@drawable/mybuttons"
android:paddingLeft="30dp"
android:paddingRight="30dp"
android:text="Track Class Activities"
android:textColor="#ffffff"
android:textSize="17dp"></Button>
</TableRow>
</TableLayout>
</RelativeLayout>
</ScrollView>
<ListView
android:id="@+id/navList"
android:layout_width="200dp"
android:layout_height="match_parent"
android:layout_gravity="left|start"
android:background="#ffeeeeee"
android:choiceMode="singleChoice" />
</android.support.v4.widget.DrawerLayout>
</LinearLayout>
我尝试在5.0.2或更低版本的设备上安装已签名的APK,并发现CalendarView根本没有显示。事实上只是显示月份和年份。 CalendarView在API 23中可见,但在其下方则不可见。任何帮助表示赞赏。
修改 这是堆栈跟踪
java.lang.NullPointerException
at android.graphics.Canvas_Delegate$11.draw(Canvas_Delegate.java:974)
at com.android.layoutlib.bridge.impl.GcSnapshot.drawOnGraphics(GcSnapshot.java:654)
at com.android.layoutlib.bridge.impl.GcSnapshot.drawInLayer(GcSnapshot.java:606)
at com.android.layoutlib.bridge.impl.GcSnapshot.draw(GcSnapshot.java:582)
at android.graphics.Canvas_Delegate.draw(Canvas_Delegate.java:937)
at android.graphics.Canvas_Delegate.drawText(Canvas_Delegate.java:960)
at android.graphics.Canvas_Delegate.native_drawText(Canvas_Delegate.java:847)
at android.graphics.Canvas_Delegate.native_drawText(Canvas_Delegate.java:859)
at android.graphics.Canvas.native_drawText(Canvas.java)
at android.graphics.Canvas.drawText(Canvas.java:1665)
at android.widget.CalendarViewLegacyDelegate$WeekView.drawWeekNumbersAndDates(CalendarViewLegacyDelegate.java:1434)
at android.widget.CalendarViewLegacyDelegate$WeekView.onDraw(CalendarViewLegacyDelegate.java:1355)
at android.view.View.draw(View.java:15231)
at android.view.View.draw(View.java:15140)
at android.view.ViewGroup.drawChild_Original(ViewGroup.java:3405)
at android.view.ViewGroup_Delegate.drawChild(ViewGroup_Delegate.java:65)
at android.view.ViewGroup.drawChild(ViewGroup.java:3405)
at android.widget.ListView.drawChild(ListView.java:3396)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3198)
at android.widget.AbsListView.dispatchDraw(AbsListView.java:2603)
at android.widget.ListView.dispatchDraw(ListView.java:3391)
at android.view.View.draw(View.java:15234)
at android.widget.AbsListView.draw(AbsListView.java:4110)
at android.view.View.draw(View.java:15140)
at android.view.ViewGroup.drawChild_Original(ViewGroup.java:3405)
at android.view.ViewGroup_Delegate.drawChild(ViewGroup_Delegate.java:65)
at android.view.ViewGroup.drawChild(ViewGroup.java:3405)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3198)
at android.view.View.draw(View.java:15138)
at android.view.ViewGroup.drawChild_Original(ViewGroup.java:3405)
at android.view.ViewGroup_Delegate.drawChild(ViewGroup_Delegate.java:65)
at android.view.ViewGroup.drawChild(ViewGroup.java:3405)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3198)
at android.view.View.draw(View.java:15138)
at android.view.ViewGroup.drawChild_Original(ViewGroup.java:3405)
at android.view.ViewGroup_Delegate.drawChild(ViewGroup_Delegate.java:65)
at android.view.ViewGroup.drawChild(ViewGroup.java:3405)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3198)
at android.view.View.draw(View.java:15138)
at android.view.ViewGroup.drawChild_Original(ViewGroup.java:3405)
at android.view.ViewGroup_Delegate.drawChild(ViewGroup_Delegate.java:65)
at android.view.ViewGroup.drawChild(ViewGroup.java:3405)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3198)
at android.view.View.draw(View.java:15234)
at android.widget.FrameLayout.draw(FrameLayout.java:598)
at android.widget.ScrollView.draw(ScrollView.java:1689)
at android.view.View.draw(View.java:15140)
at android.view.ViewGroup.drawChild_Original(ViewGroup.java:3405)
at android.view.ViewGroup_Delegate.drawChild(ViewGroup_Delegate.java:65)
at android.view.ViewGroup.drawChild(ViewGroup.java:3405)
at android.support.v4.widget.DrawerLayout.drawChild(DrawerLayout.java:1229)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3198)
at android.view.View.draw(View.java:15138)
at android.view.ViewGroup.drawChild_Original(ViewGroup.java:3405)
at android.view.ViewGroup_Delegate.drawChild(ViewGroup_Delegate.java:65)
at android.view.ViewGroup.drawChild(ViewGroup.java:3405)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3198)
at android.view.View.draw(View.java:15138)
at android.view.ViewGroup.drawChild_Original(ViewGroup.java:3405)
at android.view.ViewGroup_Delegate.drawChild(ViewGroup_Delegate.java:65)
at android.view.ViewGroup.drawChild(ViewGroup.java:3405)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3198)
at android.view.View.draw(View.java:15138)
at android.view.ViewGroup.drawChild_Original(ViewGroup.java:3405)
at android.view.ViewGroup_Delegate.drawChild(ViewGroup_Delegate.java:65)
at android.view.ViewGroup.drawChild(ViewGroup.java:3405)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3198)
at android.view.View.draw(View.java:15138)
at android.view.ViewGroup.drawChild_Original(ViewGroup.java:3405)
at android.view.ViewGroup_Delegate.drawChild(ViewGroup_Delegate.java:65)
at android.view.ViewGroup.drawChild(ViewGroup.java:3405)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3198)
at android.view.View.draw(View.java:15234)
at android.view.View.draw(View.java:15140)
at android.view.ViewGroup.drawChild_Original(ViewGroup.java:3405)
at android.view.ViewGroup_Delegate.drawChild(ViewGroup_Delegate.java:65)
at android.view.ViewGroup.drawChild(ViewGroup.java:3405)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3198)
at android.view.View.draw(View.java:15234)
at com.android.layoutlib.bridge.impl.RenderSessionImpl.render(RenderSessionImpl.java:601)
at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:323)
at com.android.ide.common.rendering.LayoutLibrary.createSession(LayoutLibrary.java:350)
at com.android.tools.idea.rendering.RenderTask$2.compute(RenderTask.java:510)
at com.android.tools.idea.rendering.RenderTask$2.compute(RenderTask.java:498)
at com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(ApplicationImpl.java:967)
at com.android.tools.idea.rendering.RenderTask.createRenderSession(RenderTask.java:498)
at com.android.tools.idea.rendering.RenderTask.access$600(RenderTask.java:72)
at com.android.tools.idea.rendering.RenderTask$3.call(RenderTask.java:610)
at com.android.tools.idea.rendering.RenderTask$3.call(RenderTask.java:607)
at com.android.tools.idea.rendering.RenderService.runRenderAction(RenderService.java:359)
at com.android.tools.idea.rendering.RenderTask.render(RenderTask.java:607)
at com.android.tools.idea.rendering.RenderTask.render(RenderTask.java:629)
at com.intellij.android.designer.designSurface.AndroidDesignerEditorPanel$7.run(AndroidDesignerEditorPanel.java:519)
at com.intellij.util.ui.update.MergingUpdateQueue.execute(MergingUpdateQueue.java:337)
at com.intellij.util.ui.update.MergingUpdateQueue.execute(MergingUpdateQueue.java:327)
at com.intellij.util.ui.update.MergingUpdateQueue$3.run(MergingUpdateQueue.java:271)
at com.intellij.util.ui.update.MergingUpdateQueue.flush(MergingUpdateQueue.java:286)
at com.intellij.util.ui.update.MergingUpdateQueue.flush(MergingUpdateQueue.java:244)
at com.intellij.util.ui.update.MergingUpdateQueue.run(MergingUpdateQueue.java:234)
at com.intellij.util.concurrency.QueueProcessor.runSafely(QueueProcessor.java:238)
at com.intellij.util.Alarm$Request$1.run(Alarm.java:352)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
答案 0 :(得分:2)
我在我的类文件中使用了try
{}
catch (\PDOException $e)
{}
,setSelectedWeekBackgroundColor
等弃用的方法。删除这些行并将其替换为xml代码。现在工作正常。
修改强> 仍然没有工作
<强> EDIT2 强> 最后工作使用硬编码高度日历