在Android中,默认情况下ImageView是一个矩形.如何在ImageView中将其设置为圆角矩形(将我的Bitmap的所有4个角切掉为圆角矩形)?
android rounded-corners imageview android-image android-imageview
我希望图像有圆角.我实现了这个xml代码并在我的图像视图中使用它.但图像与形状重叠.我正在通过异步任务下载图像.
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<corners android:radius="20dip" />
</shape>
<ImageView
android:id="@+id/trVouchersImage"
android:layout_width="55dp"
android:layout_height="55dp"
android:layout_marginLeft="8dp"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:layout_alignParentLeft="true"
android:background="@drawable/ash_arrow"
/>
Run Code Online (Sandbox Code Playgroud) 我在使用XML创建一个简单的圆角矩形时遇到了麻烦.每当我尝试将"角落"元素添加到自定义形状时,我得到:
在android.view.View.View.draw(View.java)的android.graphics.drawable.RedientDrawable.draw(GradientDrawable.java:314)上的android.graphics.Path.addRoundRect(Path.java:514)的java.lang.UnsupportedOperationException 6520)...
RES/dawable/rounded_rectangle.xml:
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<solid android:color="#ffffff"/>
<stroke android:width="3dp"
android:color="#ff000000"/>
<padding android:left="1dp"
android:top="1dp"
android:right="1dp"
android:bottom="1dp"/>
<corners android:bottomRightRadius="7dp" android:bottomLeftRadius="7dp"
android:topLeftRadius="7dp" android:topRightRadius="7dp"/>
</shape>
Run Code Online (Sandbox Code Playgroud)
使用上面的形状的简单layout.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent"
android:layout_width="fill_parent">
<View android:id="@+id/View01"
android:background="@drawable/rounded_rectangle"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
</View>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
Fyi,我正在尝试为Android 2.1编译,我已经安装了Eclipse和Android SDK的所有最新更新.这个形状是我在另一个网站上看到的东西的直接副本,但由于某种原因它不想为我工作.
谢谢.
我是android dev的新手,现在我已经尝试了几个小时为ImageView添加漂亮而光滑的圆角,但没有成功.
我尝试的第一件事就是直接对我的图像进行圆角处理,但这意味着要更改位图,因为我需要保留原始位图,而且这些都非常大,这对内存不友好.这也会导致其他困难,因为我的ImageView是流动的.
我尝试使用的第二件事是继承我的视图后的clipPath方法.这有效,但角落是别名.然后我尝试添加一个PaintFlagsDrawFilter来实现别名,但这没有用.我正在使用monodroid,我想知道这应该用于Java.
这是我的代码(C#):
public class MyImageView : ImageView
{
private float[] roundedCorner;
/**
* Contains the rounded corners for the view.
* You can define one, four or height values.
* This behaves as the css border-radius property
*
* @see http://developer.android.com/reference/android/graphics/Path.html#addRoundRect(android.graphics.RectF, float[], android.graphics.Path.Direction)
*/
public float[] RoundedCorners{
get{
return roundedCorner;
}
set{
float[] finalValue = new float[8];
int i=0;
if(value.Length == 1){
for(i=0; i<8;i++){
finalValue[i] = value[0];
}
}else if(value.Length == 4){
for(i=0; i<4;i++){
finalValue[2*i] = value[i]; …Run Code Online (Sandbox Code Playgroud) 我已经尝试了很多次,但我知道我遗漏了一些东西,请你们解释一下.. 以下是什么,我已经尝试过了
<ImageView
android:id="@+id/Dicimage"
android:layout_width="130px"
android:layout_height="100px"
android:src="@drawable/slang"
android:background="@drawable/corner"
android:padding="1dp"/>
Run Code Online (Sandbox Code Playgroud)
在资源文件夹中创建 Corner XML
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#fff"/>
<stroke android:width="0dp"
android:color="#ff000000"/>
<padding android:left="2dp"
android:top="2dp"
android:right="2dp"
android:bottom="2dp"/>
<corners android:radius="30px"/>
</shape>
Run Code Online (Sandbox Code Playgroud)
我得到的是,边框只是圆角矩形,但图像的形状仍然是矩形
我有一个列表视图与一些项目.在我的listview中,我使用自定义适配器来显示带有图像的项目.我在物品中的JSON图像来自我的图像是这样的 -

现在,我只需要圆角的图像.我如何实现这一目标?
我尝试创建带圆角的imageview.i搜索并找到xml代码
<?xml version="1.0" encoding="utf-8"?>
Run Code Online (Sandbox Code Playgroud)
<solid android:color="#00ffffff" />
<padding
android:bottom="6dp"
android:left="6dp"
android:right="6dp"
android:top="6dp" />
<corners android:radius="12dp" />
<stroke
android:width="6dp"
android:color="#ffffffff" />
Run Code Online (Sandbox Code Playgroud)
这是我的imageview xml代码
<ImageView
android:id="@+id/slidemenuuserimage"
android:layout_width="90dp"
android:layout_height="90dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_marginBottom="16dp"
android:layout_marginLeft="14dp"
android:background="@drawable/frame" />
Run Code Online (Sandbox Code Playgroud)
我有一个问题.当我以编程方式添加背景图像时,我收到了divirent结果.
slidemenuuserimage=(ImageView)findViewById(R.id.slidemenuuserimage);
slidemenuuserimage.setBackgroundResource(R.drawable.myuserimg);
Run Code Online (Sandbox Code Playgroud)
这是我的结果

如何以编程方式向左或向右添加填充.在我的选项中,这是我的问题,如果有人知道解决方案请帮助我