简体   繁体   English

Android studio 3.1 XML预览未显示某些XML布局

[英]Android studio 3.1 XML preview not showing for some XML layouts

Some layouts are shown, some just have blank, gray frame. 显示了一些布局,有些只是空白的灰色框架。 I can't seem to find a correlation between XML layouts that work and those that do not, there is a mixture of use of binding, constraint layout, varied in complexity and length, error-free. 我似乎无法找到工作的XML布局和不工作的XML布局之间的相关性,使用绑定,约束布局,复杂性和长度各不相同,无差错。 The app is compiling and running well. 该应用程序正在编译并运行良好。

Any suggestions? 有什么建议?

Clearing cache/restarting, cleaning, rebuilding had no effect on this 清除缓存/重新启动,清理,重建对此没有影响

Solution: Noticed a red error icon next to layout in preview mode. 解决方案:在预览模式下注意布局旁边的红色错误图标。 It had something to do with id resources resolver @1 . 它与id资源解析器@ 1有关。 I manually edited one of resource ids on a layout. 我在布局上手动编辑了一个资源ID。 This somehow fixed issue with rest of the layouts. 这在某种程度上修复了其余布局的问题。 Weird. 奇怪的。

Edit : It seems that problem keeps reoccurring. 编辑 :似乎问题一直在重演。 Changing theme on the preview does however help. 但是,在预览中更改主题会有所帮助。 I would also try to change preview mode to blueprint if you are having problems. 如果遇到问题,我也会尝试将预览模式更改为蓝图。

Edit 2 : I've went with Android Studio 3.2 Canary 9 and layouts are working as expected without problems. 编辑2 :我已经使用Android Studio 3.2 Canary 9和布局正常工作没有问题。 I'm guessing it had something to do with new-old bindings compiler 我猜它与新旧绑定编译器有关

Edit 3 : Oh god... problems are not ending. 编辑3 :天啊......问题没有结束。 3.2 Canary 11 uses up all given memory fast while editing layouts and then GC keeps lagging all IDE for me. 3.2 Canary 11在编辑布局时快速耗尽所有给定的内存,然后GC为我保留了所有IDE。 Need to restart IDE every 30mins. 需要每隔30分钟重启一次IDE。 I end up reverting to 3.1.1 and if things are not loading I force refresh layout as it was suggested in below comment. 我最终恢复到3.1.1,如果没有加载,我强制刷新布局,如下面的注释中所建议的那样。

For me, only "Force Refresh Layout" worked. 对我来说,只有“强制刷新布局”有效。 Restarting, re-building, cleaning didn't work. 重新启动,重建,清洁无效。

在此输入图像描述

i solved it by changing the below dependency 我通过改变下面的依赖来解决它

from

implementation 'com.android.support:appcompat-v7:28.0.0-alpha3'

to

implementation 'com.android.support:appcompat-v7:27.1.1'

I've tried pretty much everything from above and nothing worked for me. 我从上面尝试过几乎所有东西,对我来说没有任何作用。 Then I've downgraded my compileSdkVersion and targetSdkVersion 然后我降级了我的compileSdkVersiontargetSdkVersion

compileSdkVersion 27
targetSdkVersion 27

It worked! 有效! I've changed the versions back to 28 and it is still working. 我已将版本更改回28并且仍然有效。

You can change your dependency in build.gradle(module) 您可以在build.gradle(模块)中更改您的依赖项

from

implementation 'com.android.support:appcompat-v7:28.0.0-alpha3'

to

implementation 'com.android.support:appcompat-v7:28.0.0-alpha1'

I just realized this problem is from FloatingActionButton. 我刚刚意识到这个问题来自FloatingActionButton。 Remove it and the preview works. 删除它,预览工作。

I've tried pretty much everything from above and nothing worked for me. 我从上面尝试过几乎所有东西,对我来说没有任何作用。 Then I've downgraded my compileSdkVersion and targetSdkVersion 然后我降级了我的compileSdkVersion和targetSdkVersion

---> compileSdkVersion 27 ---> compileSdkVersion 27

---> targetSdkVersion 27 ---> targetSdkVersion 27

and then 然后

---> implementation 'com.android.support:appcompat-v7:28.0.0-alpha3' to --->实现'com.android.support:appcompat-v7:28.0.0-alpha3'到

---> implementation 'com.android.support:appcompat-v7:27.1.1' --->实现'com.android.support:appcompat-v7:27.1.1'

仔细检查你的布局文件是否有任何不兼容性创建一个新的布局并在该视图中添加一个textview并检查它是否正常工作,有时我们的布局包含它不应该显示的错误,请尝试这样一次并切换到“设计”.click“强制刷新布局”

Layout Screen Not displaying ? 布局屏幕不显示?

Just Open Styles.xml from --- Res -> Values -> Styles.xml 只需打开--- Res - > Values - > Styles.xml中的Styles.xml

Replace: 更换:

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">

With: 附:

<style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar">

Your Display will come immediately. 您的显示器将立即出现。 This is by just adding Base. 这只是添加Base。

for android 3.1.3 I solved it by changing the dependencies 对于Android 3.1.3我通过更改依赖项解决了它

from

implementation 'com.android.support:appcompat-v7:28.0.0-rc02'

to

implementation 'com.android.support:appcompat-v7:28.0.0-alpha1'

This is a bug in latest versions of Android Studio. 这是Android Studio最新版本中的错误。 The only way i have found to make it work is using forcing refresh layout . 我发现使其工作的唯一方法是使用强制刷新布局

Mine worked by changing custom tabs to the version 28.0.0 in my build.gradle app 我的工作是在我的build.gradle应用程序中将自定义选项卡更改为版本28.0.0

api 'com.android.support:appcompat-v7:28.0.0' api 'com.android.support:customtabs:28.0.0' api'com.android.support:appcompat-v7:28.0.0'api'com.android.support:customtabs:28.0.0'

All you had to do is go to styles.xml file and replace your parent theme from Theme.AppCompat.Light.DarkActionBar to Base.Theme.AppCompat.Light.DarkActionBar 您所要做的就是转到styles.xml文件并将您的父主题从Theme.AppCompat.Light.DarkActionBarBase.Theme.AppCompat.Light.DarkActionBar

Append Base to the default parent style 将Base附加到默认父样式

If you unable to see 'preview' with eye icon on the right of the xml text. 如果您无法通过xml文本右侧的眼睛图标看到“预览”。 You have to enable preview from the view. 您必须从视图中启用预览。 Follow this:- View -> Tool Windows -> Preview 请按照下列步骤操作: - 查看 - >工具窗口 - >预览

Open your styles.xml file. 打开styles.xml文件。

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>

That was an issue in Android Studio 3.1. 这是Android Studio 3.1中的一个问题。 Now in 3.4, there are no issues like that. 现在在3.4中,没有类似的问题。 So, it is recommended to keep up to date the Android Studio with the latest version. 因此,建议使用最新版本更新Android Studio。

除了在Activity_main.xml中将Layout更改为LinearLayout之外,无需执行任何其他操作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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