Customizing xml drawable resource with image for background in Android -
i developing android app. in app, opening activity dialog. activity background, want set image whole background, border radius. created background xml resource this.
<?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android" > <item android:drawable="@drawable/match_background_image" /> <item> <shape android:shape="rectangle" android:padding="10dp"> <corners android:bottomrightradius="5dp" android:bottomleftradius="5dp" android:topleftradius="5dp" android:toprightradius="5dp"/> </shape> </item> </layer-list>
i set resource background of linearlayout. when open activity, this
as can see there no border radius @ corners. besides, want want set scaletype cropcenter image. please possible done in xml resource please? if can be, how can fix code please? if cannot, best way please? please me.
i can give better way, have use alternative. can use cardview in android make corners round shape.
to add cardview use following in gradle dependencies,
compile 'com.android.support:cardview-v7:25.1.1'
the in activity need open dialog, change xml follows,
<?xml version="1.0" encoding="utf-8"?> <android.support.v7.widget.cardview xmlns:android="http://schemas.android.com/apk/res/android" xmlns:card_view="http://schemas.android.com/apk/res-auto" android:id="@+id/activity_dialog" android:layout_width="match_parent" android:layout_height="match_parent" card_view:cardcornerradius="10dp"> <imageview android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/your_image"/> </android.support.v7.widget.cardview>
if using activity extend appcompatactivity below,
i.e. dialogactivity extends appcompatactivity
you need change activity theme in android manifests below,
<activity android:name=".dialogactivity" android:theme="@style/theme.appcompat.dialog"></activity>
else
<activity android:theme="@android:style/theme.dialog" />
haaaaa, hard part finished, thing need call
startactivity(new intent(this, dialogactivity.class));
Comments
Post a Comment