将EditText/TextView放置在MapView Android上
我正在构建一个需要mapview和textview才能启用地点/位置选择器的应用程序。这就像“uber”,地图视图填满整个屏幕,然后用于选择位置的EditText视图叠加在地图视图的顶部。问题是我的设计xml文件将TextView放在地图视图的“后面”,这样它们就被地图覆盖而不可见了。如何使它们显示在地图视图上;而地图视图仍然覆盖100%的屏幕高度?。我的xml文件如下所示:将EditText/TextView放置在MapView Android上,android,Android,我正在构建一个需要mapview和textview才能启用地点/位置选择器的应用程序。这就像“uber”,地图视图填满整个屏幕,然后用于选择位置的EditText视图叠加在地图视图的顶部。问题是我的设计xml文件将TextView放在地图视图的“后面”,这样它们就被地图覆盖而不可见了。如何使它们显示在地图视图上;而地图视图仍然覆盖100%的屏幕高度?。我的xml文件如下所示: <?xml version="1.0" encoding="utf-8"?> <Relative
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
>
<LinearLayout
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:textColor="@color/colorPrimary"
android:text="Pickup Location"
android:id="@+id/pickup"
android:textSize="15sp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:textColor="@color/colorPrimary"
android:text="Drop Location"
android:id="@+id/drop"
android:textSize="15sp"
android:layout_alignParentLeft="true"
android:layout_below="@id/pickup"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/ride_start"
android:layout_margin="10dp"
android:textSize="15sp"
android:visibility="gone"
android:textColor="@color/colorPrimary"
android:layout_below="@+id/drop"
android:text="Start"/>
</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="MainActivity"
/>
<LinearLayout
android:layout_width="match_parent"
android:id="@+id/info"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:background="#F8CA2B"
android:gravity="center_vertical" >
<TextView
android:id="@+id/totaldistance"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="3dp"
android:textColor="#000" />
<View
android:layout_width="2dp"
android:layout_height="25dp"
android:layout_marginLeft="10dp"
android:background="#fff" />
<TextView
android:id="@+id/cost"
android:padding="3dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#000" />
</LinearLayout>
使用以下代码
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:orientation="vertical">
<TextView
android:id="@+id/pickup"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:text="Pickup Location"
android:textColor="@color/colorPrimary"
android:textSize="15sp" />
<TextView
android:id="@+id/drop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@id/pickup"
android:layout_margin="10dp"
android:text="Drop Location"
android:textColor="@color/colorPrimary"
android:textSize="15sp" />
<TextView
android:id="@+id/ride_start"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/drop"
android:layout_margin="10dp"
android:text="Start"
android:textColor="@color/colorPrimary"
android:textSize="15sp"
android:visibility="gone" />
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<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="MainActivity"
/>
<LinearLayout
android:id="@+id/info"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/map"
android:layout_centerHorizontal="true"
android:layout_marginBottom="15dp"
android:background="#F8CA2B"
android:gravity="center_vertical">
<TextView
android:id="@+id/totaldistance"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="3dp"
android:textColor="#000" />
<View
android:layout_width="2dp"
android:layout_height="25dp"
android:layout_marginLeft="10dp"
android:background="#fff" />
<TextView
android:id="@+id/cost"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="3dp"
android:textColor="#000" />
</LinearLayout>
</RelativeLayout>
</RelativeLayout>
首先设置地图分割,然后覆盖相对布局可能会有所帮助
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<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="MainActivity"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:textColor="@color/colorPrimary"
android:text="Pickup Location"
android:id="@+id/pickup"
android:textSize="15sp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:textColor="@color/colorPrimary"
android:text="Drop Location"
android:id="@+id/drop"
android:textSize="15sp"
android:layout_alignParentLeft="true"
android:layout_below="@id/pickup"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/ride_start"
android:layout_margin="10dp"
android:textSize="15sp"
android:visibility="gone"
android:textColor="@color/colorPrimary"
android:layout_below="@+id/drop"
android:text="Start"/>
</LinearLayout>
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:id="@+id/info"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:background="#F8CA2B"
android:gravity="center_vertical" >
<TextView
android:id="@+id/totaldistance"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="3dp"
android:textColor="#000" />
<View
android:layout_width="2dp"
android:layout_height="25dp"
android:layout_marginLeft="10dp"
android:background="#fff" />
<TextView
android:id="@+id/cost"
android:padding="3dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#000" />
</LinearLayout>
使用覆盖的框架布局谢谢ysl,我选择了上面Vij的答案,因为我首先看到了它。感谢您的时间,我正在使用osmdroid,并在org.osmdroid.views.MapView上替换了“您的地图片段”。它看起来很像地图上方的edittext组件。谢谢
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:circular="http://schemas.android.com/tools"
android:id="@+id/content_frame"
xmlns:app="http://schemas.android.com/apk/res-auto">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/content_frame_child">
<!--Your map fragment-->
<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="MainActivity"/>
<!--Your map fragment ends-->
</FrameLayout>
<LinearLayout
android:layout_width="match_parent"
android:id="@+id/info"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:background="#F8CA2B"
android:gravity="center_vertical" >
<TextView
android:id="@+id/totaldistance"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="3dp"
android:textColor="#000" />
<View
android:layout_width="2dp"
android:layout_height="25dp"
android:layout_marginLeft="10dp"
android:background="#fff" />
<TextView
android:id="@+id/cost"
android:padding="3dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#000" />
</LinearLayout>
</FrameLayout>