Android日期选择器未在预览中呈现

时间:2015-02-09 05:50:57

标签: android android-activity datepicker

我正在使用Android Studio 1.0.2,并将DatePicker控件插入到我的活动中。它似乎在运行时运行良好,但它一直导致预览中的渲染问题,这使得设计活动变得困难。我没有看到关于这个问题的任何帖子,但是想知道是否有人遇到过这个问题。我可以发布xml,但我认为它不会有用,因为它看起来很干净。

谢谢!

这是我得到的信息:

错误资源相关

渲染问题

android.content.res.Resources$NotFoundException   
    at com.android.layoutlib.bridge.android.BridgeContext.obtainStyledAttributes(BridgeContext.java:490)   
    at com.android.layoutlib.bridge.android.BridgeContext.obtainStyledAttributes(BridgeContext.java:93)




    <TableRow
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="0.04">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:text="Reminder (days ahead): "
            android:id="@+id/EditSpecialDay_textDate" />
    </TableRow>
    <TableRow
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_weight="0.04">

        <DatePicker
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/datePicker"
            android:layout_gravity="center_horizontal"
            android:layout_weight=".04" />
    </TableRow>



</LinearLayout>

根据要求提供堆栈(这有帮助吗?)

android.content.res.Resources $ NotFoundException         在com.android.layoutlib.bridge.android.BridgeContext.obtainStyledAttributes(BridgeContext.java:490)         在com.android.layoutlib.bridge.android.BridgeContext.obtainStyledAttributes(BridgeContext.java:93)         在android.widget.TextView.setTextAppearance(TextView.java:2484)         在android.widget.YearPickerView $ YearAdapter.getView(YearPickerView.java:132)         在android.widget.AbsListView.obtainView(AbsListView.java:2344)         在android.widget.ListView.measureHeightOfChildren(ListView.java:1270)         在android.widget.ListView.onMeasure(ListView.java:1182)         在android.view.View.measure(View.java:17430)         在android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5463)         在android.widget.FrameLayout.onMeasure(FrameLayout.java:430)         在android.view.View.measure(View.java:17430)         在android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5463)         在android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1436)         在android.widget.LinearLayout.measureVertical(LinearLayout.java:722)         在android.widget.LinearLayout.onMeasure(LinearLayout.java:613)         在android.view.View.measure(View.java:17430)         在android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5463)         在android.widget.FrameLayout.onMeasure(FrameLayout.java:430)         在android.view.View.measure(View.java:17430)         在android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5463)         在android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1436)         在android.widget.TableRow.measureChildBeforeLayout(TableRow.java:247)         在android.widget.LinearLayout.measureHorizo​​ntal(LinearLayout.java:1083)         在android.widget.TableRow.onMeasure(TableRow.java:114)         在android.view.View.measure(View.java:17430)         在android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5463)         在android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1436)         在android.widget.LinearLayout.measureVertical(LinearLayout.java:722)         在android.widget.LinearLayout.onMeasure(LinearLayout.java:613)         在android.view.View.measure(View.java:17430)         在android.widget.RelativeLayout.measureChildHorizo​​ntal(RelativeLayout.java:727)         在android.widget.RelativeLayout.onMeasure(RelativeLayout.java:463)         在android.view.View.measure(View.java:17430)         在android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5463)         在android.widget.FrameLayout.onMeasure(FrameLayout.java:430)         在android.view.View.measure(View.java:17430)         在android.widget.LinearLayout.measureVertical(LinearLayout.java:875)         在android.widget.LinearLayout.onMeasure(LinearLayout.java:613)         在android.view.View.measure(View.java:17430)         在android.widget.LinearLayout.measureVertical(LinearLayout.java:875)         在android.widget.LinearLayout.onMeasure(LinearLayout.java:613)         在android.view.View.measure(View.java:17430)         在com.android.layoutlib.bridge.impl.RenderSessionImpl.measureView(RenderSessionImpl.java:626)         在com.android.layoutlib.bridge.impl.RenderSessionImpl.render(RenderSessionImpl.java:526)         在com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:334)         在com.android.ide.common.rendering.LayoutLibrary.createSession(LayoutLibrary.java:350)         在com.android.tools.idea.rendering.RenderService $ 5.compute(RenderService.java:688)         在com.android.tools.idea.rendering.RenderService $ 5.compute(RenderService.java:677)         在com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(ApplicationImpl.java:932)         在com.android.tools.idea.rendering.RenderService.createRenderSession(RenderService.java:677)         在com.android.tools.idea.rendering.RenderService.render(RenderService.java:815)         在org.jetbrains.android.uipreview.AndroidLayoutPreviewToolWindowManager.doRender(AndroidLayoutPreviewToolWindowManager.java:646)         在org.jetbrains.android.uipreview.AndroidLayoutPreviewToolWindowManager.access $ 1700(AndroidLayoutPreviewToolWindowManager.java:82)         在org.jetbrains.android.uipreview.AndroidLayoutPreviewToolWindowManager $ 7 $ 1.run(AndroidLayoutPreviewToolWindowManager.java:589)         在com.intellij.openapi.progress.impl.ProgressManagerImpl $ 2.run(ProgressManagerImpl.java:178)         在com.intellij.openapi.progress.ProgressManager.executeProcessUnderProgress(ProgressManager.java:209)         在com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:212)         在com.intellij.openapi.progress.impl.ProgressManagerImpl.runProcess(ProgressManagerImpl.java:171)         在org.jetbrains.android.uipreview.AndroidLayoutPreviewToolWindowManager $ 7.run(AndroidLayoutPreviewToolWindowManager.java:584)         在com.intellij.util.ui.update.MergingUpdateQueue.execute(MergingUpdateQueue.java:320)         在com.intellij.util.ui.update.MergingUpdateQueue.execute(MergingUpdateQueue.java:310)         在com.intellij.util.ui.update.MergingUpdateQueue $ 2.run(MergingUpdateQueue.java:254)         在com.intellij.util.ui.update.MergingUpdateQueue.flush(MergingUpdateQueue.java:269)         在com.intellij.util.ui.update.MergingUpdateQueue.flush(MergingUpdateQueue.java:227)         在com.intellij.util.ui.update.MergingUpdateQueue.run(MergingUpdateQueue.java:217)         在com.intellij.util.concurrency.QueueProcessor.runSafely(QueueProcessor.java:238)         在com.intellij.util.Alarm $ Request $ 1.run(Alarm.java:327)         at java.util.concurrent.Executors $ RunnableAdapter.call(Executors.java:511)         at java.util.concurrent.FutureTask.run(FutureTask.java:266)         在java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)         at java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:617)         在java.lang.Thread.run(Thread.java:745)

1 个答案:

答案 0 :(得分:0)

检查以下发布的代码

对于水平视图

<?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="horizontal">

    <TableRow
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="0.04">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:text="Reminder (days ahead): "
            android:id="@+id/EditSpecialDay_textDate" />
    </TableRow>

    <TableRow
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_alignParentBottom="true"
        android:layout_weight="0.04">

        <DatePicker
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/datePicker"
            android:layout_gravity="center_horizontal" />
    </TableRow>


</LinearLayout>

垂直视图

<?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">

    <TableRow
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="0.04">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:text="Reminder (days ahead): "
            android:id="@+id/EditSpecialDay_textDate" />
    </TableRow>

    <TableRow
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_alignParentBottom="true"
        android:layout_weight="0.04">

        <DatePicker
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/datePicker"
            android:layout_gravity="center_horizontal"
             />
    </TableRow>


</LinearLayout>

基于你发布的xml,一旦从图形预览中更改api级别,可能的原因就像API级别的明智的rending问题。

XML设计不合适TableRow赋予权重,高度和宽度应为0dp所以一旦检查了我共享的代码可能有帮助。

任何可以水平或垂直使用的