天天看點

android studio 預覽報錯,Android Studio 布局預覽時 渲染錯誤

android studio 預覽報錯,Android Studio 布局預覽時 渲染錯誤

8種機械鍵盤軸體對比

本人程式員,要買一個寫代碼的鍵盤,請問紅軸和茶軸怎麼選?

錯誤 Missing classes1

2

3

4

5

6

7Missing classes

The following classes could not be found:

- com.caiyi.youle.camera.ui.CameraFilterHorizontalScrollView (Fix Build Path, Edit XML, Create Class)

- com.caiyi.youle.camera.ui.FocusImageView (Fix Build Path, Edit XML, Create Class)

- com.caiyi.youle.camera.ui.VideoProgressView (Fix Build Path, Edit XML, Create Class)

Tip: Try to build the project. Tip: Try to refresh the layout

解決方法:去掉布局檔案中,不存在的 viewModel 對象的引用。重新 build,就可以了。

error: Error: Dimension types not allowed (at ‘shadowDx’ with value ‘5dp’1

2

3

4

5

6

7

8

9

10

11

12

13

android:id="@+id/iv_filter"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:drawableTop="@drawable/ic_filter_selector"

android:gravity="center"

android:padding="8dp"

android:text="@string/filter"

android:textSize="@dimen/font_small_size"

android:shadowColor="@color/black"

android:shadowDx="5dp"

android:shadowDy="5dp"

android:shadowRadius="10dp"/>

改了隻後,還出錯,而且,XML中的值被改回去。仔細看錯誤發現,錯誤指向的XML不是原始檔案:

D:\work\videoshare_android.git\app\build\intermediates\data-binding-layout-out\_360\debug\layout\activity_camera_record_video_layout.xml

錯誤 Using the design library requires using Theme.AppCompat or a descendant1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39Using the design library requires using Theme.AppCompat or a descendant

Failed to instantiate one or more classes

android.support.design.widget.CoordinatorLayout

android.support.design.widget.AppBarLayout

android.support.design.widget.FloatingActionButton

one or more layouts are missing the layout_width or layout_height attributes

java.lang.IllegalArgumentException: You need to use a Theme.AppCompat theme (or descendant) with the design library.

at android.support.design.widget.ThemeUtils.checkAppCompatTheme(ThemeUtils.java:36)

at android.support.design.widget.CoordinatorLayout.(CoordinatorLayout.java:205)

at android.support.design.widget.CoordinatorLayout.(CoordinatorLayout.java:199)

at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)

at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)

at java.lang.reflect.Constructor.newInstance(Constructor.java:423)

at org.jetbrains.android.uipreview.ViewLoader.createNewInstance(ViewLoader.java:475)

at org.jetbrains.android.uipreview.ViewLoader.loadClass(ViewLoader.java:262)

at org.jetbrains.android.uipreview.ViewLoader.loadView(ViewLoader.java:220)

at com.android.tools.idea.rendering.LayoutlibCallbackImpl.loadView(LayoutlibCallbackImpl.java:186)

at android.view.BridgeInflater.loadCustomView(BridgeInflater.java:334)

at android.view.BridgeInflater.loadCustomView(BridgeInflater.java:345)

at android.view.BridgeInflater.createViewFromTag(BridgeInflater.java:245)

at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:727)

at android.view.LayoutInflater.inflate(LayoutInflater.java:495)

at android.view.LayoutInflater.inflate(LayoutInflater.java:397)

at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:324)

at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:429)

at com.android.ide.common.rendering.LayoutLibrary.createSession(LayoutLibrary.java:368)

at com.android.tools.idea.rendering.RenderTask$2.compute(RenderTask.java:567)

at com.android.tools.idea.rendering.RenderTask$2.compute(RenderTask.java:549)

at com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(ApplicationImpl.java:863)

at com.android.tools.idea.rendering.RenderTask.createRenderSession(RenderTask.java:549)

at com.android.tools.idea.rendering.RenderTask.lambda$inflate$1(RenderTask.java:680)

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)

配置清單

解決方法

删除 PlayerActivity 的 android:theme="@style/AppTheme.NoActionBar"

即使用 指定的樣式 android:theme="@style/AppTheme"

或者給 @style/AppTheme.NoActionBar 增加父樣式 Theme.AppCompat1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

android:allowBackup="true"

android:icon="@mipmap/ic_launcher"

android:label="@string/app_name"

android:roundIcon="@mipmap/ic_launcher_round"

android:supportsRtl="true"

android:theme="@style/AppTheme">

android:name=".PlayerActivity"

android:label="@string/title_activity_player"

android:theme="@style/AppTheme.NoActionBar">

@style/AppTheme.NoActionBar 和 @style/AppTheme 樣式的代碼1

2

3

4

5

6

7

8

9

10

11

12

@color/colorPrimary

@color/colorPrimaryDark

@color/colorAccent

false

true

gradle.build 指定的依賴1

2

3compile 'com.android.support:appcompat-v7:25.3.1'

compile 'com.android.support.constraint:constraint-layout:1.0.2'

compile 'com.android.support:design:25.3.1'

出錯的 Activity 的定義1public class PlayerActivity extends AppCompatActivity

出錯的布局1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

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

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"

tools:context="work.wangxiang.lansodemo.PlayerActivity">

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:theme="@style/AppTheme.AppBarOverlay">

android:id="@+id/toolbar"

android:layout_width="match_parent"

android:layout_height="?attr/actionBarSize"

android:background="?attr/colorPrimary"

app:popupTheme="@style/AppTheme.PopupOverlay" />

android:id="@+id/fab"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_gravity="bottom|end"

android:layout_margin="@dimen/fab_margin"

app:srcCompat="@android:drawable/ic_dialog_email" />

把 activity 樣式回複成原來的,重新打開 AS,又不出錯了。

錯誤:Layout fidelity warning1

2

3

4

5

6

7

8

9

10

android:id="@+id/iv_filter"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:drawableTop="@drawable/ic_filter_selector"

android:gravity="center"

android:padding="8dp"

android:text="@string/filter"

android:textSize="@dimen/font_small_size"

android:shadowColor="@color/white" />

accurate

英 [ˈækjərət] 美 [ˈækjərɪt]

adj.精确的,準确的;正确無誤的

fidelity

英 [fɪˈdeləti] 美 [fɪˈdɛlɪti,faɪ-]

n.保真度;逼真;忠誠,忠實;盡責

The graphics preview in the layout editor may not be accurate:

Paint.setShadowLayer is not supported

error-the-graphics-preview-in-the-layout-editor-may-not-be-accurate-paint-set

It means the preview doesn’t know how to implement setShadowLayer. This means the preview won’t look exactly like the result rendered on the device. Which is one of many reasons why you shouldn’t trust the preview app- always test your layouts on a physical device before assuming they’re done.