安卓中圆形控件的实现

安卓自带控件中几乎没有圆形控件,但在实际开发过程中圆形控件更能给用户更好的视觉效果。

先看一下我们要实现的效果:


要实现这种效果的话先要在drawable文件夹下新建一个Android XML文件,我们起名为circle。代码如下

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="oval">
    <size android:width="100dp"
        android:height="100dp"/>
    <stroke android:width="1dp"
        android:color="#929292"/>
<solid android:color="#FFFFFF"/>
</shape>
其中shape属性设置为oval,表示为椭圆形,然后在size中设置宽高,宽高相同,表示圆形

stroke主要用来设置边框颜色和边框的宽度

solide主要用于设置圆内的颜色


然后我们该写布局文件了

<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"
    tools:context=".MainActivity" >

   <ImageView 
       android:id="@+id/iv"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:layout_centerInParent="true"
       android:scaleType="centerInside"
       android:src="@drawable/accountpager_pen_icon"
       android:background="@drawable/cricle"
       />

</RelativeLayout>

在布局文件中添加了一个Imageview控件,居中放置,在background中引用我们刚才写的那个xml文件

这时候圆会出现,我们可以在圆中添加一个图片,我在里面添加了一个笔的图片,是在src中把图片引入进去的

我们在添加图片的时候可能要注意了,如果我们添加的图片过大,可能这时的圆会变形,我们可以通过修改我们写的那个cricle文件的长宽,也可以修改图片的大小

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值