Android Studio无法呈现简单的布局

时间:2015-02-24 07:04:50

标签: android android-studio

为什么在Android Studio中这种相对简单的布局渲染?

当我在Android Studio中打开此文件时,我看到"渲染问题"而不是渲染的布局预览。以及下面显示的错误列表。但是在设备上运行时看起来很好。

然而,对布局的一些调整将导致它被渲染......

  • 将按钮设置为宽度为0dp
  • 交换LinearLayouts layout_1和layout_2
  • 的顺序
  • 将layout_1或layout_2的高度降低为100dp
  • 从滚动视图中删除LinearLayouts

当我将项目迁移到Gradle和API 21时,这只会成为一个问题。


将无法在Android Studio中呈现的布局

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">


<ScrollView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:id="@+id/scrollView2" >

    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/d">

        <LinearLayout
            android:orientation="vertical"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:id="@+id/layout_1"
            android:layout_marginTop="@dimen/list_item_vertical_padding">

            <TextView
                android:layout_width="match_parent"
                android:layout_height="400dp"
                android:text="New Text"
                android:id="@+id/textView2" />

        </LinearLayout>

        <LinearLayout
            android:orientation="vertical"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:id="@+id/layout_2"
            android:clickable="false"
            android:layout_marginTop="@dimen/list_item_vertical_padding">

            <LinearLayout
                android:orientation="vertical"
                android:layout_width="fill_parent"
                android:layout_height="300dp"
                android:id="@+id/interface_2"
                android:showDividers="end"
           android:divider="@android:drawable/divider_horizontal_textfield">

                <!-- Stuff gets inflated into here -->

            </LinearLayout>

            <LinearLayout
                android:orientation="horizontal"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:id="@+id/stats_button_container"
                android:focusableInTouchMode="false">

                <Button
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:text="@string/all_data"
                    android:id="@+id/stats_range_button_1"
                    android:layout_gravity="center"
                    android:textAlignment="center"
                    android:singleLine="false"
                    android:clickable="true"
                    android:layout_margin="5dp"
                    android:textColor="@color/standard_text_on_white"
                    android:layout_weight="1" />

                <Button
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:text="@string/six_months_of_data"
                    android:id="@+id/stats_range_button_2"
                    android:layout_gravity="center"
                    android:textAlignment="center"
                    android:singleLine="false"
                    android:clickable="true"
                    android:layout_margin="5dp"
                    android:textColor="@color/standard_text_on_white"
                    android:layout_weight="1" />

                <Button
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:text="@string/one_month_of_data"
                    android:id="@+id/stats_range_button_3"
                    android:layout_gravity="center"
                    android:textAlignment="center"
                    android:singleLine="false"
                    android:layout_margin="5dp"
                    android:textColor="@color/standard_text_on_white"
                    android:layout_weight="1" />
            </LinearLayout>
        </LinearLayout>

    </LinearLayout>
</ScrollView>


  

显示java.lang.NullPointerException       在android.view.ViewGroup_Delegate.drawShadow(ViewGroup_Delegate.java:74)       在android.view.ViewGroup_Delegate.drawChild(ViewGroup_Delegate.java:61)       在android.view.ViewGroup.drawChild(ViewGroup.java:3404)       在android.view.ViewGroup.dispatchDraw(ViewGroup.java:3198)       在android.view.View.draw(View.java:15017)       在android.view.ViewGroup.drawChild_Original(ViewGroup.java:3404)       在android.view.ViewGroup_Delegate.drawChild(ViewGroup_Delegate.java:53)       在android.view.ViewGroup.drawChild(ViewGroup.java:3404)       在android.view.ViewGroup.dispatchDraw(ViewGroup.java:3198)       在android.view.View.draw(View.java:15017)       在android.view.ViewGroup.drawChild_Original(ViewGroup.java:3404)       在android.view.ViewGroup_Delegate.drawChild(ViewGroup_Delegate.java:53)       在android.view.ViewGroup.drawChild(ViewGroup.java:3404)       在android.view.ViewGroup.dispatchDraw(ViewGroup.java:3198)       在android.view.View.draw(View.java:15017)       在android.view.ViewGroup.drawChild_Original(ViewGroup.java:3404)       在android.view.ViewGroup_Delegate.drawChild(ViewGroup_Delegate.java:53)       在android.view.ViewGroup.drawChild(ViewGroup.java:3404)       在android.view.ViewGroup.dispatchDraw(ViewGroup.java:3198)       在android.view.View.draw(View.java:15117)       在android.widget.FrameLayout.draw(FrameLayout.java:592)       在android.widget.ScrollView.draw(ScrollView.java:1689)       在android.view.View.draw(View.java:15022)       在android.view.ViewGroup.drawChild_Original(ViewGroup.java:3404)       在android.view.ViewGroup_Delegate.drawChild(ViewGroup_Delegate.java:53)       在android.view.ViewGroup.drawChild(ViewGroup.java:3404)       在android.view.ViewGroup.dispatchDraw(ViewGroup.java:3198)       在android.view.View.draw(View.java:15017)       在android.view.ViewGroup.drawChild_Original(ViewGroup.java:3404)       在android.view.ViewGroup_Delegate.drawChild(ViewGroup_Delegate.java:53)       在android.view.ViewGroup.drawChild(ViewGroup.java:3404)       在android.view.ViewGroup.dispatchDraw(ViewGroup.java:3198)       在android.view.View.draw(View.java:15017)       在android.view.ViewGroup.drawChild_Original(ViewGroup.java:3404)       在android.view.ViewGroup_Delegate.drawChild(ViewGroup_Delegate.java:53)       在android.view.ViewGroup.drawChild(ViewGroup.java:3404)       在android.view.ViewGroup.dispatchDraw(ViewGroup.java:3198)       在android.view.View.draw(View.java:15117)       在android.view.View.draw(View.java:15022)       在android.view.ViewGroup.drawChild_Original(ViewGroup.java:3404)       在android.view.ViewGroup_Delegate.drawChild(ViewGroup_Delegate.java:53)       在android.view.ViewGroup.drawChild(ViewGroup.java:3404)       在android.view.ViewGroup.dispatchDraw(ViewGroup.java:3198)       在android.view.View.draw(View.java:15117)       在com.android.layoutlib.bridge.impl.RenderSessionImpl.render(RenderSessionImpl.java:587)       在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:708)       在com.android.tools.idea.rendering.RenderService $ 5.compute(RenderService.java:697)       在com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(ApplicationImpl.java:932)       在com.android.tools.idea.rendering.RenderService.createRenderSession(RenderService.java:697)       在com.android.tools.idea.rendering.RenderService.render(RenderService.java:816)       在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:471)       at java.util.concurrent.FutureTask $ Sync.innerRun(FutureTask.java:334)       at java.util.concurrent.FutureTask.run(FutureTask.java:166)       在java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)       at java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:615)       在java.lang.Thread.run(Thread.java:724)

0 个答案:

没有答案