Image Not Cropping
main.xml
<RelativeLayoutxmlns: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" ><ImageViewandroid:id="@+id/image"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_centerHorizontal="true"
/></RelativeLayout>
OnCreate
publicclassMainActivityextendsActivity {
@OverrideprotectedvoidonCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ImageView rl=(ImageView)findViewById(R.id.image);
Bitmapbitmap= BitmapFactory.decodeResource(getResources(), R.drawable.testing); // your desire drawable image.
rl.setImageBitmap(getRoundedCornerImage(bitmap, 10, 10, this));
}
Original image
Output
Below links help me to achieve my goal:
Border over a bitmap with rounded corners in Android
Creating ImageView with round corners
Solution 2:
try your back.xml some thing like like this instead of giving a rectangle background image.
<?xml version="1.0" encoding="UTF-8"?><layer-listxmlns:android="http://schemas.android.com/apk/res/android"><itemandroid:drawable="#ff00ff >
</item>
<item>
<shape android:shape="rectangle" ><solid/><strokeandroid:width="1dip"android:color="#225786" /><cornersandroid:radius="10dip"/><paddingandroid:left="0dip"android:top="0dip"android:right="0dip"android:bottom="0dip" /></shape></item>
Solution 3:
Another alternative to what Raj has posted is to use a background image with transparency at the corner.
The BEST solution, as your background is simple, is to use a 9-patch, which is the Android-native solution to the majority of background images: http://developer.android.com/guide/topics/graphics/2d-graphics.html#nine-patch, which is similar in style to how some website backgrounds are drawn.
Android also has it's own 9-patch creator bundled with the sdk: http://developer.android.com/tools/help/draw9patch.html, so it's easy enough to edit your own png files, then apply the 9-patch to the layout. The advantage of 9-patches is that they also handle the resizing the UI for you, meaning you won't encounter as many problems when using your app on different screens
Solution 4:
Use your shape in combination with an image with rounded corners.
You can use AndroidQuery to load the image with rounded corners. See http://code.google.com/p/android-query/wiki/ImageLoading#Rounded_Corner
Stringurl="http://www.vikispot.com/z/images/vikispot/android-w.png";
ImageOptionsoptions=newImageOptions();
options.round = 15;
aq.id(R.id.image).image(url, options);
Solution 5:
I think you should have done it like this.
<layer-listxmlns:android="http://schemas.android.com/apk/res/android"><item><shape><solidandroid:color="@color/back" /><strokeandroid:width="1dip"android:color="#225786" /><cornersandroid:radius="10dip"/><paddingandroid:left="0dip"android:top="0dip"android:right="0dip"android:bottom="0dip" /></shape></item>
If the background is not a color but it is a bitmap, you should follow this beautiful guide http://www.curious-creature.org/2012/12/11/android-recipe-1-image-with-rounded-corners/
Post a Comment for "Image Not Cropping"