繁体   English   中英

为什么我不能在活动中放置小部件? (Android)

[英]Why do i can't place widgets on my activity ? (Android)

我创建了一个名为“ PechhulpActivity”的Google Maps活动,我想在其上方放置一个按钮。 但是,如果我要编辑活动,则会出现有关片段标签的错误:

A <fragment> 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.

这是我的布局文件夹结构的屏幕截图,首先我以为我缺少诸如content_pechhulp.xml之类的文件。 如果是这样,我该如何创建正确的? 我想自定义诸如信息窗口之类的Google Maps活动,并希望其中包含一个按钮等。希望大家能帮帮我。

在此处输入图片说明

编辑:(activity_pechhulp.xml)

<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.doppler.stackingcoder.pechhulp.PechhulpActivity" />

尝试将RelativeLayout用作父对象,然后添加带有片段的子对象以及另一个诸如TextView或Button的视图。 它将放置在地图上方。

为此使用Relativelayout或FrameLayout作为权限

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:map="http://schemas.android.com/apk/res-auto"
            xmlns:tools="http://schemas.android.com/tools"
            android:layout_width="match_parent"
            android:layout_height="match_parent">
            <fragment
            android:id="@+id/map"
            android:name="com.google.android.gms.maps.SupportMapFragment"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
          tools:context="com.doppler.stackingcoder.pechhulp.PechhulpActivity"/>
            <Button 
               android:layout_width="wrap_content"
               android:layout_height="wrap_content"
               android:text="@string/your_string_value"/>
   </RelativeLayout>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM