调整"Google maps V2"的大小以占用屏幕的一半而不是整个屏幕

Los*_*Cid 2 java android google-maps-api-2 google-maps-android-api-2

我现在正在开发一个Android项目:我想做的是让地图的屏幕上半部分显示,另一半用于我稍后写的信息.

我的问题是地图占据整个屏幕,我尝试了不同的布局(相对,网格)和膨胀另一个布局,但地图总是占用整个屏幕,无论我使用什么.

这是我的代码:

public class Map extends SherlockMapFragment implements IPage, View.OnClickListener {

private GoogleMap    googleMap;
private Marker       marker;
ViewGroup            view;


public Map() {
    super();
}
    @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    view = (ViewGroup) inflater.inflate(R.layout.map_page, null);

    googleMap = getMap();
    googleMap.setMyLocationEnabled(true);
    marker = googleMap.addMarker(new MarkerOptions().title("Event").position(new LatLng(0, 0)));

    final LatLng latLng = new LatLng(48.8146, 2.39525);      

    googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng, 16.0f));
    marker.setPosition(latLng);

    return view;
}
Run Code Online (Sandbox Code Playgroud)

和xml:

<?xml version="1.0" encoding="utf-8"?>
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:orientation="vertical" >

 <LinearLayout
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   android:layout_weight="1.0"
   android:orientation="vertical" > 

  <fragment
    android:id="@+id/fragment_map"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_weight="1" />
</LinearLayout>

 <LinearLayout
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   android:layout_weight="1.0"
   android:orientation="vertical" >

   <TextView 
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     android:id="@+id/infotext">          
   </TextView>

 </LinearLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

再次,地图工作没有任何问题,但它需要整个屏幕,我真的不明白为什么.另外,我正在使用lib SherlockBar(这导致我实现地图的一些问题).

我非常感谢任何帮助,我在开发Java/eclipse方面仍然很新,所以经常会出现错误.谢谢!

G.T*_*.T. 9

如果您希望将屏幕拆分为两个相等的部分,则只需使用以下布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <fragment
        android:id="@+id/fragment_map"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="50" />

    <TextView 
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="50"
        android:id="@+id/infotext" />          

</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

由于您只有两个视图,因此您无需将它们包装到其他视图中LinearLayout.

Fragment和设置相同的重量TextView是关键.它会给屏幕的一半(以高度的方向LinearLayout垂直的)每个View.