Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
274 views
in Technique[技术] by (71.8m points)

android - Adding rounded corners to a mapview

I'm trying to code a simple MapActivity which uses the following layout (only contains the mapview for the moment, as I plan to add share the screen with a ListView in the future) :

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    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="200dip"
    android:enabled="true"
    android:clickable="true"
    android:apiKey="mykey"
    android:layout_alignParentBottom="true" />
</RelativeLayout>

I have applied a simple shape to the mapview in order to have round corners and a stroke :

<?xml version="1.0" encoding="UTF-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
     android:shape="rectangle"> 
     <corners android:bottomRightRadius="10dp"
              android:bottomLeftRadius="10dp" 
              android:topLeftRadius="10dp"
              android:topRightRadius="10dp"/> 
     <stroke  android:width="3dp"
              android:color="@color/bordure_tables" />
</shape>

I use the following to apply the shape :

mapView.setBackgroundResource(R.layout.map);

Problem is that it does not have any effect and I can't see my rounded corners, nor the stroke.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Just wrote a tutorial to have rounded corners on a MapView it's done programmatically so should scale well to all devices:

http://www.anddev.org/novice-tutorials-f8/rounded-corners-map-view-t56908.html

Once you have added the custom view class you can just instantiate a rounded mapview like so:

<com.blundell.tut.ui.widget.RoundedMapView
   android:layout_width="fill_parent"
   android:layout_height="fill_parent"/>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...