简体   繁体   中英

Android Studio Layout Preview disappeared

For my main_activity , the layout preview disappeared after i was debugging.

I have 2 other layouts in this Project, in which i can perfectly see the layout in the preview.

Also the component tree says: nothing to show
There is no rendering error showing up, below is xml

在此输入图像描述

Thanks for your help!

Greetings Michael

Have you tried Rebuilding the project, re-opening Android Studio, Invalidate Caches? That is if you are sure you did nothing and it just disappeared.

If that doesn't work, you could try saving the XML code in a txt file, deleting the xml layout, creating an empty one and pasting back the code.

Update: What if you surround your LinearLayout with a ScrollView and then move the app:layout_behavior="@string/appbar_scrolling_view_behavior" to the ScrollView instead. I think everything should work fine then.

 <ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">
        your ImageView and TextViews here
    </LinearLayout>
</ScrollView>

You may have seen that you cannot see anything in "component tree" and have -nothing to show- in the "properties" section and also there is "android..ComponentLayout" showing in the preview built of the emulator.

I myself had tried different methods, but found the most convenient method to just remove the 3 lines of the code in the Main_Activity.xml file or you can just paste the following code or compare it with this one :

<?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
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"
>

I have found the solution. In fact there is a bug in android studio. In my case the problem is that when I enable the tabStripEnabled from "Properties" window, the component tree shows "Nothing to show" and when I disable it, everything goes well again. So I solved this problem by coding programmatically :

tabHost.getTabWidget().setStripEnabled(true);

So I think you should to examine everything one by one in order to find the solution. I hope this could be helpful.

I have encountered this problem, but I am by modifying the configuration in the build.gragle file to solve this problem:

在此输入图像描述

在此输入图像描述

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