Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/179.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 在运行时更改Imageview的角半径_Android_Imageview_Android Drawable - Fatal编程技术网

Android 在运行时更改Imageview的角半径

Android 在运行时更改Imageview的角半径,android,imageview,android-drawable,Android,Imageview,Android Drawable,大家好,这是我的xml文件。我想在运行时更改Imageview的角半径,这样应该更改Imageview中位图的角半径。是否有人知道我如何执行此任务 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/mainContainer" android:layout_width="match_parent" android:layout_heig

大家好,这是我的xml文件。我想在运行时更改Imageview的角半径,这样应该更改Imageview中位图的角半径。是否有人知道我如何执行此任务

<RelativeLayout
 xmlns:android="http://schemas.android.com/apk/res/android" 
   android:id="@+id/mainContainer"
   android:layout_width="match_parent"
   android:layout_height="wrap_content"
   android:gravity="center"
   >

 <TableLayout 
     android:id="@+id/firstpicTable"
     android:layout_width="102.5dp"
     android:layout_height="200dp"
     android:background="@drawable/tableborder"
     android:layout_marginTop="5dp"
     android:padding="0.5dp"
     android:layout_marginBottom="5dp"
             >
              <ImageView
         android:id="@+id/image1"
         android:layout_width="fill_parent"
         android:layout_height="fill_parent"
         android:scaleType="fitXY"

         android:background="@android:color/white"
         android:contentDescription="@string/app_name"
         />


 </TableLayout>

  <TableLayout 
     android:id="@+id/secondtpicTable"
     android:layout_width="102.5dp"
     android:layout_height="200dp"
     android:layout_marginTop="5dp"
      android:background="@drawable/tableborder"
      android:padding="0.5dp"

     android:layout_toRightOf="@+id/firstpicTable"
     >

     <ImageView 
         android:id="@+id/image223"
         android:layout_width="match_parent"
         android:layout_height="match_parent"
          android:focusable="true"
         android:background="@android:color/white"
         android:contentDescription="@string/app_name"
         android:scaleType="fitXY"

         />
 </TableLayout>

   <TableLayout 
     android:id="@+id/thirddtpicTable"
     android:layout_width="102.5dp"
     android:layout_height="200dp"
     android:layout_marginTop="5dp"

     android:layout_toRightOf="@+id/secondtpicTable"
      android:padding="0.5dp"
      android:background="@drawable/tableborder"

     android:gravity="center">
     <ImageView 
         android:id="@+id/image3"
         android:layout_width="match_parent"
         android:layout_height="match_parent"
         android:background="@android:color/black"
         android:scaleType="fitXY"
         android:focusable="true"
         android:contentDescription="@string/app_name"

         />
 </TableLayout>


就像Romain Guy在他的博客[1]中写道的那样,您可以通过实现
Drawable
并使用
canvas.drawRoundRect()

如果要在运行时改变角半径,则可以更新可绘制文件中的属性(例如,类似于
mCornerRadius
的整数),并调用
invalidateSelf()
触发重画


[1]

为什么不在可绘制中创建形状,并像这样在ImageView中使用

round_shape.xml

<?xml version="1.0" encoding="utf-8"?>
<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:radius="30dp"/> 
</shape>

拐角处
标记下提供您自己的自定义半径值