Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 在包含谷歌地图的片段上方放置两个文本视图_Android_Google Maps_Android Fragments_Google Maps Android Api 2 - Fatal编程技术网

Android 在包含谷歌地图的片段上方放置两个文本视图

Android 在包含谷歌地图的片段上方放置两个文本视图,android,google-maps,android-fragments,google-maps-android-api-2,Android,Google Maps,Android Fragments,Google Maps Android Api 2,下面的代码显示了两个文本视图,下面是一个片段,其中显示了谷歌地图的地图。但我仍然无法以这种方式显示它们: <RelativeLayout 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"

下面的代码显示了两个文本视图,下面是一个片段,其中显示了谷歌地图的地图。但我仍然无法以这种方式显示它们:

<RelativeLayout 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="${relativePackage}.${activityClass}" >


<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:layout_marginLeft="27dp"
    android:layout_marginTop="35dp"
    android:layout_alignParentBottom="true"
    android:text="@string/pos_actual" />

<TextView
    android:id="@+id/txtGeoposition"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignTop="@+id/textView1"
    android:layout_toRightOf="@+id/textView1"
    android:layout_alignParentBottom="true"
    android:layout_above="@+id/map"
    android:textAppearance="?android:attr/textAppearanceLarge" />

<fragment
    android:id="@+id/map"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_above="@+id/textView1"
    class="com.google.android.gms.maps.MapFragment" />

此外,我还想限制片段的高度,以避免填充父布局的其余部分,仅几个像素的高度,因为在地图下方我想放置其他控件来显示

我如何实现这种控制以这种方式放置它们

先谢谢你

我的代码已更新:

<RelativeLayout 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="${relativePackage}.${activityClass}" >


<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:layout_marginLeft="20dp"
    android:layout_marginTop="20dp"
    android:layout_marginBottom="20dp"
    android:text="@string/pos_actual" />

<TextView
    android:id="@+id/txtGeoposition"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignTop="@+id/textView1"
    android:layout_toRightOf="@+id/textView1"
    android:layout_above="@+id/map"
    android:textAppearance="?android:attr/textAppearanceLarge" />

<fragment
    android:id="@+id/map"
    android:layout_width="fill_parent"
    android:layout_height="match_parent"
    android:layout_below="@+id/textView1"
    class="com.google.android.gms.maps.MapFragment" />

<LinearLayout
        android:id="@+id/footerLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:gravity="bottom"
        android:layout_centerHorizontal="true"
        android:layout_alignParentBottom="true">

        <TextView
    android:id="@+id/textView2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginLeft="20dp"
    android:layout_marginTop="20dp"
    android:layout_marginBottom="20dp"
    android:text="@string/pos_actual" />
</LinearLayout>


您需要在片段之后声明文本视图


如果你想把空间放在底部,就要设置一个边距,或者使用<代码> LayOutOUT= =“@ + ID/SoMeVIEWD”引用底部的视图(用对齐PARTRONTURL PAR实例)。< /P> < P> <强>尝试这种方式,希望这将有助于你解决你的问题< /强> 查看它非常简单,您只需要在framelayout下使用textview即可

<RelativeLayout 
android:layout_width="match_parent"
android:layout_height="match_parent" >

<fragment
    android:id="@+id/mapfrag"
    android:name="com.google.android.gms.maps.MapFragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="96dip"
        android:orientation="vertical"
        android:weightSum="2" >

        <TextView
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:gravity="center"
            android:text="Text View 1"
            android:textColor="#000"
            android:textSize="16sp" />

        <TextView
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:gravity="center"
            android:text="Text View 2"
            android:textColor="#000"
            android:textSize="16sp" />
    </LinearLayout>
</FrameLayout>


代码最终更新并更正:

<RelativeLayout 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="${relativePackage}.${activityClass}" >


<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:layout_marginLeft="20dp"
    android:layout_marginTop="20dp"
    android:layout_marginBottom="20dp"
    android:text="@string/pos_actual" />

<TextView
    android:id="@+id/txtGeoposition"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignTop="@+id/textView1"
    android:layout_toRightOf="@+id/textView1"
    android:layout_above="@+id/map"
    android:textAppearance="?android:attr/textAppearanceLarge" />

<fragment
    android:id="@+id/map"
    android:layout_width="fill_parent"
    android:layout_height="match_parent"
    android:layout_below="@+id/textView1"
    class="com.google.android.gms.maps.MapFragment"
    android:layout_above="@+id/footerLayout" />

<LinearLayout
        android:id="@+id/footerLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:gravity="bottom"
        android:layout_centerHorizontal="true"
        android:layout_alignParentBottom="true">

        <TextView
    android:id="@+id/textView2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginLeft="20dp"
    android:layout_marginTop="20dp"
    android:layout_marginBottom="20dp"
    android:text="@string/pos_actual" />
</LinearLayout>


在片段上方放置两个文本视图:从两个文本视图中删除
alignParentBottom
。另外,在片段中,将上面的内容更改为下面的内容。我想我可以限制碎片的高度,因为不填充布局的其余部分?由你选择。我将其设置为填充(匹配父项)剩余空间。或者您可以使用wrap_内容。或者你可以将其他一些视图锚定在底部,并将地图也设置在该视图的上方。你想要的相对视图中的任何内容都可以锚定在其侧面(顶部、底部、右侧、左侧)。甚至只是另一个文本视图。或者整个布局。最后我可以在屏幕的底部放置一个布局。有关详细信息,请参阅我的代码更新。谢谢,Funkystein在片段上方输入两个文本视图