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"></bitmap>
back.xml
<?xml version="1.0" enCoding="UTF-8"?><@R_188_3419@ xmlns:androID="http://schemas.androID.com/apk/res/androID"> <item androID:drawable="@drawable/tile_mode" /> <item> <shape> <solID/> <stroke androID:wIDth="1dip" androID:color="#225786" /> <corners androID:radius="10dip"/> <padding androID:left="0dip" androID:top="0dip" androID:right="0dip" androID:bottom="0dip" /> </shape> </item>
layout.xml
<linearLayout androID:ID="@+ID/frame1" androID:background="@drawable/back" androID:layout_wIDth="fill_parent" androID:layout_height="wrap_content"> </linearLayout>
我将图像设置为此布局的背景,并绘制边框,但问题是图像是正方形的,边缘锐利,而我在xml中绘制的边框是圆角.那么如何使图像也有圆角?
解决方法 这是一个解决方案,你必须圆形到你的主要布局背景和内部保持您的图像与您的愿望图像:如下所示:
back.xml
这将使您的形象圆角
<?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>
更新
挖了很多东西后,我碰到了已经在stackoverflow上发布的解决方案
Changing Image as Rounded Corner
How to make an ImageView to have rounded corners
步骤1@
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>
第2步@
做一个功能,使用画布四舍五入到你的位图.
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,bitmap.getWIDth(),bitmap.getHeight()); final RectF rectF = new RectF(rect); final float roundPx = pixels; paint.setAntiAlias(true); canvas.drawARGB(0,0); paint.setcolor(color); canvas.drawRoundRect(rectF,roundPx,paint); paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN)); canvas.drawBitmap(bitmap,rect,paint); return output; }
步骤3 @
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));总结
以上是内存溢出为你收集整理的android – 具有中风的圆角的位图图像全部内容,希望文章能够帮你解决android – 具有中风的圆角的位图图像所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)