【问题标题】:Android Studio Rendering fragment issueAndroid Studio 渲染片段问题
【发布时间】:2016-04-24 21:12:07
【问题描述】:
目前,我正在尝试使用 android studio 制作一个谷歌地图应用程序。
现在,一切都很好,除了一件事,当我转到“设计”选项卡时,在 XML 文件中我有这条 Redering 消息:
渲染问题 标签允许布局文件
在运行时动态包含不同的布局。在布局编辑
时间要使用的具体布局是未知的。你可以选择哪个
您希望在编辑布局时预览的布局...
主要问题是我无法在我的布局中使用任何 gui 组件,我搜索了我的问题,我了解到由于这个错误,人们看不到他们的地图,但他们可以放置文本字段、小部件、布局等
但对我来说,我的预览完全冻结了,我无法进行任何修改。
Picture of my android studio page.
【问题讨论】:
标签:
android
android-layout
android-fragments
android-studio
【解决方案1】:
由于您可以使用代码动态更改片段,因此 android studio 不知道在设计时要显示哪种布局。这是你错误的原因。
要明确告诉 android 显示哪个布局,请将 tools:layout="@layout/Your_layout_name" 属性添加到您的片段。
您告诉的错误描述下方还有一个快捷链接。只需单击链接,android 就会为您添加它,您将在布局中看到片段,没有呈现错误消息。
详细示例:
<?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>
【解决方案3】:
只需将此设计用于片段。这解决了我的问题。另外,请参阅this 链接
<fragment
android:id = "@+id/ma"
android:name = "com.google.android.gms.maps.SupportMapFragment"
android:layout_width = "match_parent"
android:layout_height = "match_parent"
tools:context = "com.example.demomaps.MapsActivity"
/>
【解决方案4】:
是的,我很容易解决了这个问题。只需忽略该消息并单击呈现消息下方显示的行。
实际上片段包含布局内部,如果它不包括它必须包含的显示警告,您可以简单地忽略警告下方的此消息,然后此渲染问题将得到解决。