简体   繁体   中英

Android Studio UI Preview rendering problems

I am quite new to android programming. I am using android studio 1.4 and at one point I noticed that the UI preview is no longer working in a specific project. It tells me that I have rendering problems. I tryied cleaning up and rebuilding but it did not work. In other projects or new projects I create the preview works just fine. Any ideas how I can fix this.

The stack trace I get is:

    android.content.res.Resources$NotFoundException
at com.android.layoutlib.bridge.android.BridgeContext.obtainStyledAttributes(BridgeContext.java:620)
at android.content.res.Resources_Theme_Delegate.obtainStyledAttributes(Resources_Theme_Delegate.java:71)
at android.content.res.Resources$Theme.obtainStyledAttributes(Resources.java:1512)
at android.widget.TextView.<init>(TextView.java:728)
at android.widget.Button.<init>(Button.java:109)
at android.widget.Button.<init>(Button.java:105)
at android.widget.Button.<init>(Button.java:101)
at sun.reflect.GeneratedConstructorAccessor111.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
at android.view.LayoutInflater.createView(LayoutInflater.java:619)
at android.view.BridgeInflater.onCreateView(BridgeInflater.java:102)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:694)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:762)
at android.view.BridgeInflater.createViewFromTag(BridgeInflater.java:141)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:835)
at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:70)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:811)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
at android.view.LayoutInflater_Delegate.parseInclude(LayoutInflater_Delegate.java:197)
at android.view.LayoutInflater.parseInclude(LayoutInflater.java:879)
at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:831)
at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:70)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:811)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:394)
at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:223)
at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:426)
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:888)
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:366)
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$6.run(AndroidDesignerEditorPanel.java:480)
at com.intellij.util.ui.update.MergingUpdateQueue.execute(MergingUpdateQueue.java:320)
at com.intellij.util.ui.update.MergingUpdateQueue.execute(MergingUpdateQueue.java:310)
at com.intellij.util.ui.update.MergingUpdateQueue$2.run(MergingUpdateQueue.java:254)
at com.intellij.util.ui.update.MergingUpdateQueue.flush(MergingUpdateQueue.java:269)
at com.intellij.util.ui.update.MergingUpdateQueue.flush(MergingUpdateQueue.java:227)
at com.intellij.util.ui.update.MergingUpdateQueue.run(MergingUpdateQueue.java:217)
at com.intellij.util.concurrency.QueueProcessor.runSafely(QueueProcessor.java:238)
at com.intellij.util.Alarm$Request$1.run(Alarm.java:351)
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)

and the xml file is the following:

    <?xml version="1.0" encoding="utf-8"?>

<TextView
    android:text="@string/select_technical_area"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_marginTop="10dp"
    android:id="@+id/technical_area"
    android:textSize="16dp" />
<Spinner
    android:id="@+id/spinner1"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_below="@+id/technical_area"
    android:layout_alignParentStart="true"
    android:layout_alignEnd="@+id/telecommunication_center"></Spinner>

<TextView
    android:text="@string/select_telecommunication_center"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/telecommunication_center"
    android:layout_below="@+id/spinner1"
    android:layout_alignParentStart="true"
    android:layout_marginTop="20dp"
    android:textSize="16dp" />
<Spinner
    android:id="@+id/spinner2"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_below="@+id/telecommunication_center"
    android:layout_alignParentStart="true"
    android:layout_alignEnd="@+id/telecommunication_center"></Spinner>>

<TextView
    android:text="Select Facility"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/KV"
    android:layout_below="@+id/spinner2"
    android:layout_alignParentStart="true"
    android:layout_marginTop="20dp"
    android:textSize="16dp" />
<Spinner
    android:id="@+id/spinner3"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_below="@+id/KV"
    android:layout_alignParentStart="true"
    android:layout_alignEnd="@+id/spinner2"></Spinner>

<Button
    style="?android:attr/buttonStyleSmall"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Show Facility"
    android:id="@+id/button1"
    android:layout_below="@+id/spinner3"
    android:layout_alignParentStart="true"
    android:layout_marginTop="10dp"
    android:onClick="showClick"/>


<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Disarm Facility"
    android:id="@+id/button3"
    android:layout_below="@+id/button1"
    android:layout_alignParentStart="true"
    android:layout_marginTop="10dp"/>

<TextView
    android:text="@string/seyk"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/seyk"
    android:layout_below="@+id/button3"
    android:layout_alignParentStart="true"
    android:layout_marginTop="10dp"
    android:textSize="20dp"
    android:textColor="#000000"
    />

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="SOS"
    android:id="@+id/button4"
    android:textSize="56dp"
    android:layout_alignParentBottom="true"
    android:layout_alignParentStart="true"
    android:layout_alignParentEnd="true"
    android:elegantTextHeight="true"
    android:textAlignment="center"
    android:longClickable="true"
    android:textAppearance="@android:drawable/alert_dark_frame"
    android:textStyle="bold"
    android:textColor="#FF0000" />

Thank you in advance!!!

You have to lay all the elements on a father layout like RelativeLayout or better (in my opinion) a LinearLayout . So, your layout file must look like this :

<LinearLayout 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:orientation="vertical"
tools:context=".MainActivity">


    <TextView
        android:text="@string/select_technical_area"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_marginTop="10dp"
        android:id="@+id/technical_area"
        android:textSize="16dp" />
    <Spinner
        android:id="@+id/spinner1"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_below="@+id/technical_area"
        android:layout_alignParentStart="true"
        android:layout_alignEnd="@+id/telecommunication_center"></Spinner>

    <TextView
        android:text="@string/select_telecommunication_center"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/telecommunication_center"
        android:layout_below="@+id/spinner1"
        android:layout_alignParentStart="true"
        android:layout_marginTop="20dp"
        android:textSize="16dp" />
    <Spinner
        android:id="@+id/spinner2"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_below="@+id/telecommunication_center"
        android:layout_alignParentStart="true"
        android:layout_alignEnd="@+id/telecommunication_center"></Spinner>>

    <TextView
        android:text="Select Facility"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/KV"
        android:layout_below="@+id/spinner2"
        android:layout_alignParentStart="true"
        android:layout_marginTop="20dp"
        android:textSize="16dp" />
    <Spinner
        android:id="@+id/spinner3"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_below="@+id/KV"
        android:layout_alignParentStart="true"
        android:layout_alignEnd="@+id/spinner2"></Spinner>

    <Button
        style="?android:attr/buttonStyleSmall"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Show Facility"
        android:id="@+id/button1"
        android:layout_below="@+id/spinner3"
        android:layout_alignParentStart="true"
        android:layout_marginTop="10dp"
        android:onClick="showClick"/>


    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Disarm Facility"
        android:id="@+id/button3"
        android:layout_below="@+id/button1"
        android:layout_alignParentStart="true"
        android:layout_marginTop="10dp"/>

    <TextView
        android:text="@string/seyk"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/seyk"
        android:layout_below="@+id/button3"
        android:layout_alignParentStart="true"
        android:layout_marginTop="10dp"
        android:textSize="20dp"
        android:textColor="#000000"
        />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="SOS"
        android:id="@+id/button4"
        android:textSize="56dp"
        android:layout_alignParentBottom="true"
        android:layout_alignParentStart="true"
        android:layout_alignParentEnd="true"
        android:elegantTextHeight="true"
        android:textAlignment="center"
        android:longClickable="true"
        android:textAppearance="@android:drawable/alert_dark_frame"
        android:textStyle="bold"
        android:textColor="#FF0000" />

</LinearLayout>

If your screen needs scrolling then you have to add all this in a ScrollView .

我遇到了同样的问题,我想您有ImageBackground或除颜色以外的其他颜色作为背景,您必须将android android:popupBackground="#c5212121"到xml文件中的微调android:popupBackground="#c5212121" ,在这种情况下,我将透明黑色作为背景颜色,但是您当然可以更改它的颜色,还必须将android:background="00ffffff"到微调器中,它会创建微调器的背景而不是下拉菜单,我将其设置为透明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM