简体   繁体   English

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

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

I have created a Google Maps activity called 'PechhulpActivity' and i want to place a button over it. 我创建了一个名为“ PechhulpActivity”的Google Maps活动,我想在其上方放置一个按钮。 But if i want to edit the activity it gives me the error about fragment tags: 但是,如果我要编辑活动,则会出现有关片段标签的错误:

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.

Here is a screenshot of my layout folder structure, first i thought i was missing a file like content_pechhulp.xml. 这是我的布局文件夹结构的屏幕截图,首先我以为我缺少诸如content_pechhulp.xml之类的文件。 If so, how can i create the correct one? 如果是这样,我该如何创建正确的? I want to customize the Google maps activity like the info window and i want a button inside of it etc. I hope you guys can help me out. 我想自定义诸如信息窗口之类的Google Maps活动,并希望其中包含一个按钮等。希望大家能帮帮我。

在此处输入图片说明

Edit: (activity_pechhulp.xml) 编辑:(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" />

Try using RelativeLayout as Parent and then add the child with fragment and another view like TextView or Button. 尝试将RelativeLayout用作父对象,然后添加带有片段的子对象以及另一个诸如TextView或Button的视图。 It will placed above the map. 它将放置在地图上方。

use a Relativelayout or FrameLayout as parrent for this 为此使用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.

相关问题 为什么我无法在Android应用程序中开始活动? - Why i can't start activity in my android app? 为什么我不能将小部件拖放到Android Studio的工具栏中? - Why can't I drag and drop widgets into a toolbar in Android Studio? 为什么我的进度条活动指示器无法在我的 Kotlin Android 应用程序中显示更长时间 - Why can't I get my progress bar activity indicator to display longer in my Kotlin Android app 为什么在“位置”标签中看不到任何更改 - Why can't I see any changes in my “Place” tab 我不能在 Android Studio 的图像下放置 textview? - I can't place textview under my Image in Android Studio? 我可以将已安装应用程序中的小部件添加到我的应用程序活动中吗 - Can I add widgets from installed apps to my application activity 如何在Android Studio中放置模型文件? 以及如何从普通班级而不是活动中加载它? - Where do I place a model file in android studio? and how can I load it from a normal class, not an activity? 在Android中,如何检测为什么我的活动得以恢复? - In Android, how can I detect why my activity was resumed? 为什么我不能使用包名称访问我的活动? - Why can't I access my activity with the package name? 为什么我不能从我的活动中调用此服务? - Why can't I call this Service from my Activity?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM