Is there a way to implement rounded corners to a Mapfragment?
I haven't tried this, but I'd put a view with rounded corners and a transparent middle on top of the mapView / mapFragment.
That is, put the mapFragment and the rounded corner view in a FrameLayout with both filling the FrameLayout, then make the middle of the rounded corner view transparent.
For further clarification, you could do it in a layout as follows:-
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<fragment
xmlns:map="http://schemas.android.com/apk/res-auto"
android:id="@+id/mapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.MapFragment" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/rounded_background"
android:orientation="vertical" >
</LinearLayout>
</FrameLayout>
The rounded_background is a 9-patch with rounded corners and a transparent middle. E.g.
Hope that helps,
Ryan
Add rounded corners in border in Maps Fragment and remove the Fragment background
try add this line to RelativeLayout
or fragment
android:background="@drawable/map_border_2"
I hope it will work with you
how to display android mapfragment view rounded shape
Yes, it possible. Cover the MapFragment
with another layout, and set for this layout a 9-patch background, that will cover it the way you want, take a look at this question I asked on the same topic not long ago:
Is there a way to implement rounded corners to a Mapfragment?
Adding transparent rounded corners to google map
Well I guess you have stumbled on this question I asked regarding the same topic:
Is there a way to implement rounded corners to a Mapfragment?
But in this case I needed a solid color corners. I don't see an easy way to perform what you
ask for. There is no way to added rounded corners to the map "out of the box" so you will need to cover those corners with some other texture, typically it would be a 9-patch texture, that could stretch accordingly to the screen size.
You can take a look at this blog post on 9-patchs I wrote and maybe try to create a
semi-transparent texture that will fit you needs:
9-Patch guide
Round corners of MapFragment and ConstraintLayout in CardView
Enclosing the mapview in a cardview and changing the radius of the cardview can be a nice shot.
<android.support.v7.widget.CardView
android:layout_width="300dp"
android:layout_height="350dp"
app:cardCornerRadius="12dp">
<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:cameraZoom="13"
app:liteMode="true"
app:mapType="normal" />
</android.support.v7.widget.CardView>
I really think your view hierarchy is quite nested and will amount to redundancy...(Good use of one Constraint layout can yield same interface, you have about 3). I guess you have to work on that.
Besides, you can add some margin to the map..., shift it from the edges. ( I hope that is what you want to achieve )
Using a Layout to Make Rounded Corners affect on image
well, with FrameLayout or RelativeLayout you can easily stack a second layer on top of you imageview like:
<FrameLayout
android:layout_width="60dp"
android:layout_width="60dp">
<ImageView android:id="@+id/myimage"
android:layout_width="60dp"
android:layout_height="60dp"
android:src="@drawable/myrealimage" />
<ImageView android:id="@+id/my_roundedcorner_overlay"
android:layout_width="60dp"
android:layout_height="60dp"
android:src="@drawable/myoverlaywithroundedcornersandtransparentcenter" />
</FrameLayout>
however, be warned this causes overdraw and makes your layout more complex.
You could also set the real image as a background to you ImageView and the overlay as the ImageViews src, however don't set a padding in this case (also loading images from the web with a library probably won't work anymore)
Cleanest solution is to create a custom widget extending ImageView and override its onDraw method, paint to the canvas using a bitmapshader, similar to http://www.curious-creature.org/2012/12/11/android-recipe-1-image-with-rounded-corners/ pretty much the same, but do it once and reuse as often as you want.
Bitmap image with rounded corners with stroke
This is one of solution in which you have to make round to your main layout background
and inside keep your imageview with your desire image:
something like below:
back.xml
This will make your image to round corner
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<stroke android:width="1dp" android:color="#dd7b7a"/>
<corners android:bottomRightRadius="10dp" android:bottomLeftRadius="10dp"
android:topLeftRadius="10dp" android:topRightRadius="10dp"/>
<solid android:color="#dd7b7a"/>
</shape>
tile_mode.xml
<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/background"
android:tileMode="repeat" />
layout.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"
android:gravity="center"
>
<LinearLayout
android:padding="4dip"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/back"
android:gravity="center_horizontal"
>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/tile_mode"
/>
</LinearLayout>
</LinearLayout>
Updated
After digging lots, I came across on of solution which already posted on stackoverflow
Changing Image as Rounded Corner
How to make an ImageView to have rounded corners
step1@
main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
tools:context=".MainActivity" >
<ImageView
android:id="@+id/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
/>
</RelativeLayout>
Step2@
Make one function which make rounded to your bitmap using canvas.
public static Bitmap getRoundedCornerBitmap(Bitmap bitmap, int pixels) {
Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap
.getHeight(), Config.ARGB_8888);
Canvas canvas = new Canvas(output);
final int color = 0xff424242;
final Paint paint = new Paint();
final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
final RectF rectF = new RectF(rect);
final float roundPx = pixels;
paint.setAntiAlias(true);
canvas.drawARGB(0, 0, 0, 0);
paint.setColor(color);
canvas.drawRoundRect(rectF, roundPx, roundPx, paint);
paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
canvas.drawBitmap(bitmap, rect, rect, paint);
return output;
}
step3@
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ImageView image=(ImageView)findViewById(R.id.image);
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.testing);
image.setImageBitmap(getRoundedCornerBitmap(bitmap, 20));
Related Topics
How to Add .So Files to an Android Library Project Using Gradle 0.7+
Launching an Android Application from the Browser
Get Current Visible Text in Textview
Switching Between Fragment View
Moving an Image Using Accelerometer of Android
How to Send Location of the Device on Server When Needed
How to Detect If Android Device Is Paired with Android Wear Watch
Swiperefreshlayout + Webview When Scroll Position Is at Top
Httpclient on Android:Nohttpresponseexception Through Umts/3G
5.1 Crash - a Taskdescription's Primary Color Should Be Opaque
How to Set an Imageview's Image from a String
Where Does Local.Properties Go for Android Project
Creating a Dialogpreference from Xml
Android Cardview Remove Padding
Inflate Layout Programmatically Within Another Layout
How to Dynamically Change an App Icon Like Calendar App Does