目前,我正在尝试使用 android studio 制作一个谷歌地图应用。
现在,一切都很好,除了一件事,当我转到“设计”选项卡时,在 XML 文件中我有这个 Redering 消息:
Rendering Problems A tag allows a layout file to dynamically include different layouts at runtime. At layout editing time the specific layout to be used is not known. You can choose which layout you would like previewed while editing the layout...
主要问题是我无法在我的布局中使用任何 gui 组件,我搜索了我的问题,我了解到由于这个错误,人们看不到他们的 map ,但他们可以放置文本字段、小部件,布局等 但对我来说,我的预览完全卡住,无法进行任何修改。
最佳答案
由于您可以使用代码动态更改 fragment ,android studio 不知道在设计时显示哪个布局。这就是你错误的原因。
要明确告诉 android 要显示哪个布局,请将 tools:layout="@layout/Your_layout_name"
属性添加到您的 fragment 。
您所告知的错误描述下方还有一个快捷方式链接。只需单击链接,android 就会为您添加它,您将在布局中看到没有呈现错误消息的 fragment 。
有关详细示例:
<?xml version="1.0" encoding="utf-8"?>
<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"
tools:context="com.example.insane.fragmenttest.MainActivity">
<fragment
android:id="@+id/testFragmentID"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.example.insane.fragmenttest.WorkOutDetails"
tools:layout="@layout/fragment_work_out_details" /> <!-- This is the line you want to add. -->
</LinearLayout>
关于Android Studio 渲染 fragment 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36828942/