问题
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. 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 . I manually edited one of resource ids on a layout. 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. I'm guessing it had something to do with new-old bindings compiler
Edit 3: Oh god... problems are not ending. 3.2 Canary 11 uses up all given memory fast while editing layouts and then GC keeps lagging all IDE for me. Need to restart IDE every 30mins. 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.
回答1:
For me, only "Force Refresh Layout" worked. Restarting, re-building, cleaning didn't work.
回答2:
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'
回答3:
I've tried pretty much everything from above and nothing worked for me.
Then I've downgraded my compileSdkVersion
and targetSdkVersion
compileSdkVersion 27
targetSdkVersion 27
It worked! I've changed the versions back to 28 and it is still working.
回答4:
You can change your dependency in build.gradle(module)
from
implementation 'com.android.support:appcompat-v7:28.0.0-alpha3'
to
implementation 'com.android.support:appcompat-v7:28.0.0-alpha1'
回答5:
I just realized this problem is from FloatingActionButton. Remove it and the preview works.
回答6:
I've tried pretty much everything from above and nothing worked for me. Then I've downgraded my compileSdkVersion and targetSdkVersion
---> compileSdkVersion 27
---> targetSdkVersion 27
and then
---> implementation 'com.android.support:appcompat-v7:28.0.0-alpha3' to
---> implementation 'com.android.support:appcompat-v7:27.1.1'
回答7:
Carefully check your layout-file for any incompatibilities create a new layout and add one textview in that view and check whether it will be working fine or not, sometimes our layout contains error it shouldn't showing, please try this way once and switch to "Design".click "force refresh layout"
回答8:
Layout Screen Not displaying ?
Just Open Styles.xml from --- Res -> Values -> 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.
回答9:
This is a bug in latest versions of Android Studio. The only way i have found to make it work is using forcing refresh layout .
回答10:
Mine worked by changing custom tabs to the version 28.0.0 in my build.gradle app
api 'com.android.support:appcompat-v7:28.0.0' api 'com.android.support:customtabs:28.0.0'
回答11:
for android 3.1.3 I solved it by changing the dependencies
from
implementation 'com.android.support:appcompat-v7:28.0.0-rc02'
to
implementation 'com.android.support:appcompat-v7:28.0.0-alpha1'
回答12:
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
Append Base to the default parent style
回答13:
If you unable to see 'preview' with eye icon on the right of the xml text. You have to enable preview from the view. Follow this:- View -> Tool Windows -> Preview
回答14:
No need to do anything else other than just changing your Layout to LinearLayout in Activity_main.xml
回答15:
Open your styles.xml
file.
<!-- 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. Now in 3.4, there are no issues like that. So, it is recommended to keep up to date the Android Studio with the latest version.
来源:https://stackoverflow.com/questions/49534777/android-studio-3-1-xml-preview-not-showing-for-some-xml-layouts