gpt4 book ai didi

android - 带有 TextView 和按钮的 MapFragment 在单独的 UI 段中

转载 作者:行者123 更新时间:2023-11-30 00:46:34 26 4
gpt4 key购买 nike

我的 MapFragment 有问题,我不知道如何让它不填满屏幕。我需要有一个 MapFragment 来停在我的 TextView 上。我附上一张图片,可以更好地描述我需要它的外观。现在我的 MapFragment 填满了屏幕,textview 被放置在 MapFragment 的顶部。

然后我的 TextView 顶部有两个按钮。这没关系。

这是我想要的样子:

enter image description here

希望你能帮上忙!

这是布局:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_alignBottom="@id/activity_main"
android:layout_width="match_parent"
android:weightSum="10"
android:keepScreenOn="true"
android:layout_height="match_parent">


<LinearLayout
android:id="@+id/linelay"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">

<fragment android:name="com.google.android.gms.maps.SupportMapFragment"
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_weight="9"
android:layout_height="wrap_content"
tools:context="com.example.MapsActivity"
tools:layout="@layout/activity_main"/>


</LinearLayout>

<ToggleButton
android:text="ToggleButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:id="@+id/toggleButton" />

<Button
android:text="@string/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@id/toggleButton"
android:layout_alignParentRight="true"
android:onClick="clearMap"
android:id="@+id/button1" />


<TextView
android:id="@+id/text1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Hello World!"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_alignParentBottom="true"
android:background="@drawable/frame" />

</RelativeLayout>

最佳答案

这是一种方法。使用 LinearLayout 作为外部布局,并使用布局权重定义不同部分的高度。

这比使用硬编码 dp 值定义任一部分的高度要好。对高度使用布局权重将更好地动态调整不同的屏幕尺寸。

<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.danielnugent.mapapplication.MapsActivity"
android:orientation="vertical"
android:weightSum="1">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="vertical"
android:layout_weight=".8">
<fragment
android:id="@+id/map"
class="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="vertical"
android:layout_weight=".2">

<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView Text Here"
android:layout_marginLeft="40dp"
android:layout_marginStart="40dp"
android:lineSpacingExtra="14sp"
android:textSize="18sp"
android:layout_above="@+id/button1"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />

<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 1"
android:layout_marginRight="18dp"
android:layout_marginEnd="18dp"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_above="@+id/button1" />

<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 2"
android:layout_alignParentBottom="true"
android:layout_alignLeft="@+id/button2"
android:layout_alignStart="@+id/button2" />

</RelativeLayout>
</LinearLayout>

结果:

enter image description here

关于android - 带有 TextView 和按钮的 MapFragment 在单独的 UI 段中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41703798/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com