Android Fragments Android Studio渲染碎片问题

9wbgstp7  于 2023-02-19  发布在  Android
关注(0)|答案(4)|浏览(173)

目前,我正在尝试用android studio开发一款谷歌Map应用。
现在,一切都很好,除了一件事,当我去“设计”选项卡,在XML文件中,我有这个Redering消息:
渲染问题标签允许布局文件在运行时动态包含不同的布局。在布局编辑时,要使用的特定布局是未知的。您可以选择要在编辑布局时预览的布局...
主要的问题是,我不能在我的布局中使用任何图形用户界面组件,我搜索了我的问题,我明白了这个错误,人们看不到他们的Map,但他们可以把文本字段,小部件,布局等,但对我来说,我的预览是完全冻结,我不能做任何修改。
Picture of my android studio page.

gkn4icbw

gkn4icbw1#

由于你可以动态地改变代码片段,android studio不知道在设计时显示哪个布局,这就是你出错的原因。添加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>
nfzehxib

nfzehxib2#

尝试使用设计时布局属性。http://tools.android.com/tips/layout-designtime-attributes
这些属性指导Android Studio如何在布局编辑器中呈现运行时属性。
我认为您应该将tools:showIn="@layout/activity_maps"包含在google_maps_api.xml<fragment>部分中

ttp71kqs

ttp71kqs3#

只是使用这个设计的片段。这解决了我的问题。另外,请参阅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"
     />
up9lanfz

up9lanfz4#

是的,我很容易就解决了这个问题。只需忽略消息,然后单击显示在渲染消息下面的行。实际上,片段包含布局内部,如果它不包括它的显示警告,它必须包含,你可以简单地忽略警告下面的消息,然后这个渲染问题将得到解决。

相关问题