首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何在Android中设置边框和旋转位图图像?

如何在Android中设置边框和旋转位图图像?
EN

Stack Overflow用户
提问于 2015-03-25 05:39:15
回答 4查看 803关注 0票数 0

我绝对是机器人的新手。我有一个从URL获取的位图。我想在屏幕顶部的一个图像视图的中间显示它。我还想在图像周围画一个边框。目前,当我使用以下代码旋转时,它只会转到顶部:

代码语言:javascript
运行
复制
private static void imageWithBorders(ImageView im, View image){
Matrix matrix = new Matrix();
im.setScaleType(ScaleType.MATRIX);   //required
matrix.setRotate((float) -20f);
im.setImageMatrix(matrix);
im.setImageBitmap(bmp);
}

当我设置这样的图像不是在中心,也是如何设置边界围绕它?

我期待着这样的事情。

实现这一目标的任何可能方法都是值得赞赏的。请帮帮我!

提前谢谢!

EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2015-03-25 09:25:21

代码语言:javascript
运行
复制
<LinearLayout 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:background="#10171C"
android:gravity="center" >


    <ImageView
        android:id="@+id/sample"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:contentDescription="@null"
        android:rotation="10"
        android:padding="2dp"
        android:background="@drawable/shadow_gray"
        android:src="@drawable/ic_launcher" />

</LinearLayout>

在可绘制的shadow_gray.xml中创建xml文件

代码语言:javascript
运行
复制
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle" >

    <corners
        android:bottomLeftRadius="0dp"
        android:bottomRightRadius="0dp"
        android:radius="2dp"
        android:topRightRadius="0dp" />

    <stroke
        android:width="1dp"
        android:color="@android:color/white" />

</shape>

它不会在xml的图形布局中显示旋转。但是当它运行的时候,它就会像这样出现。

票数 1
EN

Stack Overflow用户

发布于 2015-03-25 05:45:00

用这个:

代码语言:javascript
运行
复制
android:rotation="20"// 20 is the angle

将此代码交给ImageView

若要边框,请将ImageView放在LinearLayout中

并将此代码提供给ImageView标记中的

代码语言:javascript
运行
复制
android:padding="5dp"

如果你想要边框颜色,那就这么做

给LinearLayout背景加上一个颜色

代码语言:javascript
运行
复制
android:background="#ffffff"//#ffffff is the color code
票数 1
EN

Stack Overflow用户

发布于 2015-03-25 05:48:28

Matrix mymatrix = new Matrix();

imageView.setScaleType(ScaleType.MATRIX);

mymatrix.postRotate((float) angle, pivX, pivY);

imageView.setImageMatrix(mymatrix);

这将旋转您的图像视图。

设置padding=1px并将背景色设置为线性布局,THen将有1px边框。如果您需要进一步的澄清,请通知我

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29248230

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档