向地图视图添加圆角

发布于 2024-10-20 19:37:40 字数 1252 浏览 5 评论 0原文

我正在尝试编写一个简单的 MapActivity,它使用以下布局(目前仅包含地图视图,因为我计划将来添加与 ListView 共享屏幕):

<?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>

我已按顺序将简单的形状应用于地图视图具有圆角和描边:

<?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>

我使用以下内容来应用形状:

mapView.setBackgroundResource(R.layout.map);

问题是它没有任何效果,我看不到我的圆角,也看不到描边。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

白首有我共你 2024-10-27 19:37:41

刚刚写了一个教程,在 MapView 上设置圆角,它是通过编程完成的,因此应该可以很好地扩展到所有设备:

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

添加自定义视图类后您可以像这样实例化一个圆形地图视图:

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

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"/>
姜生凉生 2024-10-27 19:37:41

您是否尝试过为其分配填充?

<padding 
     android:left="2dp" 
     android:top="2dp" 
     android:right="2dp" 
     android:bottom="2dp" /> 

所以你的笔画和半径应该是可见的。

Have you tried assigning it a padding?

<padding 
     android:left="2dp" 
     android:top="2dp" 
     android:right="2dp" 
     android:bottom="2dp" /> 

So your strokes and radius should be visible.

太阳男子 2024-10-27 19:37:41

因此,我通过执行以下操作实现了这种效果:我创建了一个名为 round_corners 的 9 补丁可绘制对象并将其放置在我的可绘制文件夹中,然后使用以下 xml 来绘制地图:

    <FrameLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">/

        <com.google.android.maps.MapView
            android:id="@+id/center_map"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:clickable="true"
            android:apiKey="your_key"
        />

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:orientation="vertical"
            android:background="@drawable/round_corners"  
        ></LinearLayout>
    </FrameLayout>

So I've achieved this affect by doing following: I've created a 9-patch drawable called round_corners and placed it in my drawable folder, then I use following xml to plot the map:

    <FrameLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">/

        <com.google.android.maps.MapView
            android:id="@+id/center_map"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:clickable="true"
            android:apiKey="your_key"
        />

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:orientation="vertical"
            android:background="@drawable/round_corners"  
        ></LinearLayout>
    </FrameLayout>
随风而去 2024-10-27 19:37:41

我能够实现这一点,创建一个圆形可绘制对象,如下所示:

<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
    <solid android:color="@android:color/transparent" />
    <stroke android:width="10dp" android:color="@color/color_gray5_eeeeee" />
    <corners android:radius="10px" />
</shape>

然后使用线性布局和与可绘制笔划宽度相同大小的边距,如下所示:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background_gray_rectangle_rounded_corners"
android:orientation="vertical">

<com.google.android.gms.maps.MapView
    android:id="@+id/map_details_map_view"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_marginTop="10dp"
    android:layout_marginBottom="10dp"
    android:clickable="true"
    android:enabled="true" />
</LinearLayout>

I was able to achieve this creating a rounded drawable like this:

<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
    <solid android:color="@android:color/transparent" />
    <stroke android:width="10dp" android:color="@color/color_gray5_eeeeee" />
    <corners android:radius="10px" />
</shape>

then using a linear layout and a margin of the same size of the drawable stroke width, like this:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background_gray_rectangle_rounded_corners"
android:orientation="vertical">

<com.google.android.gms.maps.MapView
    android:id="@+id/map_details_map_view"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_marginTop="10dp"
    android:layout_marginBottom="10dp"
    android:clickable="true"
    android:enabled="true" />
</LinearLayout>
独自←快乐 2024-10-27 19:37:41

只需将Mapview放入CardView即可

 <android.support.v7.widget.CardView
        android:layout_width="match_parent"
        android:layout_height="100dp"
        android:elevation="0dp"
        app:cardCornerRadius="5dp">

     <com.google.android.gms.maps.MapView
            android:layout_width="match_parent"
            android:layout_height="match_parent"/>

 </android.support.v7.widget.CardView>

Just put the Mapview into a CardView

 <android.support.v7.widget.CardView
        android:layout_width="match_parent"
        android:layout_height="100dp"
        android:elevation="0dp"
        app:cardCornerRadius="5dp">

     <com.google.android.gms.maps.MapView
            android:layout_width="match_parent"
            android:layout_height="match_parent"/>

 </android.support.v7.widget.CardView>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文