Jon*_*nas 2 layout android android-linearlayout android-mapview
我关注了Hello Views,谷歌地图视图,现在我想TextView在下面添加一个MapView.我只是改变了布局文件main.xml,并放在MapView与TextView垂直LinearLayout.我的Eclipse设置为自动构建它,但是当我在模拟器中运行应用程序时,我只能看到它MapView.
我怎样才能添加TextView下面的MapView?
这是我的布局main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<com.google.android.maps.MapView
android:id="@+id/mapview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true"
android:apiKey="my key"
/>
<TextView
android:id="@+id/textview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="My TextView"
/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
你可能想尝试一下RelativeLayout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="@+id/MyTextView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
android:layout_alignParentBottom="true" />
<com.google.android.maps.MapView
android:id="@+id/map"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:apiKey="Your api key"
android:enabled="true"
android:clickable="true"
android:layout_above="@+id/MyTextView"" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
我无法让MapViews与LinearLayouts一起使用
你遇到的问题是你正在使用android:layout_height="fill_parent"你的MapView.
如果你愿意,我不会得到:
TextView要在地图上MapView,留出空间TextView在第一种情况下使用a <RelativeLayout>而不是a <LinearLayout>和play android:layout_alignParentBottom="true"for for TextView.
在第二种情况下,使用android:layout_weight.我没有打开eclipse但放置android:layout_weight="1"到TextView应该就够了.