I'm using mapview
on main Relative Layout
I want to mapView to be completely rounded.
I searched it for in internet get answer saying that I should make new drawable xml and add it to Layout that I want to make it rounded by setBackgorund(R.drawable.xxxx)
.
so, I made layout_bg.xml
in drawable folder.
layout_bg.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<!-- solid background -->
<solid android:color="#ffffba54"/>
<!-- border-->
<stroke
android:color="#ffff206a"
android:width="2dp"
/>
<corners android:radius="25dp"/>
<!-- different corners with different radius-->
<!--corners
android:bottomLeftRadius="5dp"
android:topLeftRadius="10dp"
android:topRightRadius="15dp"
android:bottomRightRadius="20dp"
/-->
</shape>
</item>
but It's not working at all. so, I tried to do it in programmatically.
MainActivity.java
setContentView(R.layout.activity_main);
mapView = new MapView(this);
ViewGroup mapViewContainer = (ViewGroup)
findViewById(R.id.map_view);
mapViewContainer.setBackgroundDrawable(R.drawable.layout_bg);
<--- Here I get error. because R.drawable.layout_bg is int
Log.e("mp","mapView2");
mapViewContainer.addView(mapView);
activity_main.xml
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="11dp"
android:layout_marginStart="11dp"
android:layout_marginTop="85dp"
android:text="aaaaaaaa" />
<RelativeLayout
android:id="@+id/map_view"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
/>
</RelativeLayout>
Use (MainActivity.this).getResources().getDrawable(R.drawable.layout_bg)
then you wont get the error.. !!