【问题标题】:Fragment covers entire android editing screen片段覆盖整个android编辑屏幕
【发布时间】:2019-11-02 11:13:50
【问题描述】:

所以我有一个看起来像这样的应用程序:

但是在创建 gui 的过程中,我总是必须使用文本模式创建按钮等,因为谷歌地图片段挡住了我的整个设计屏幕:

这是我的文件:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_margin="5dp"
    android:orientation="horizontal">

    <EditText
        android:id="@+id/editText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="4"
        android:hint="Search Location" />

    <Button
        android:id="@+id/search_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="0.5"
        android:onClick="onMapSearch"
        android:text="Search" />

</LinearLayout>


<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="horizontal">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Type: " />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:onClick="onNormalMap"
        android:text="Normal" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:onClick="onSatelliteMap"
        android:text="Satellite" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:onClick="onTerrainMap"
        android:text="Terrain" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:onClick="onHybridMap"
        android:text="Hybrid" />

</LinearLayout>

<fragment xmlns:android="http://schemas.android.com/apk/res/android"
    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.viralandroid.googlemapsandroidapi.MapsActivity" />

</LinearLayout>

我该如何解决这个问题?即使我只有谷歌地图片段而没有任何其他组件,它仍然会阻塞我的整个编辑屏幕......

【问题讨论】:

  • 试试 layout_weghit
  • 试试 layout_weghit
  • @MohammadSommakia 我需要把它放在哪里?

标签: android google-maps android-fragments maps designmode


【解决方案1】:

可能的解决方案:

  • 重新启动 Android Studio(解决了我的问题)
  • 卸载 Android Studio 并重新安装
  • 检查 build.gradle 库版本(必要时更新)

【讨论】:

    【解决方案2】:

    将 layout_height 属性更改为 wrap_content,然后将视图与父底部对齐

        layout_weight="wrap_content"
        android:layout_alignParentBottom="true"
    

    否则你可以使用约束布局

    否则,代替片段标签使用框架布局,然后在您的代码中将片段膨胀到框架布局上。

    在片段膨胀方面需要帮助? Android: how to load fragment into FrameLayout

    【讨论】:

      猜你喜欢
      • 2020-02-07
      • 2015-05-17
      • 1970-01-01
      • 2016-11-13
      • 1970-01-01
      • 2021-05-09
      • 1970-01-01
      • 2020-07-19
      • 1970-01-01
      相关资源
      最近更新 更多