Android:shape设置corners(圆角)不能正常显示问题

本文探讨了在Android中,shape设置的圆角corners无法正常显示的问题。原因是上层控件的背景覆盖了设置了shape的下层控件,导致圆角被遮盖。解决方案是调整布局中控件的层级关系或背景设置。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

我遇到的情况是:在shape中设置corners与solid后只有soild的颜色正常显示,corners未显示成圆角。

原因:错误不在shape,而是布局中background设置,上层控件的background覆盖下层控件background(设置shape

  的控件)而导致的圆角被遮盖的问题。

布局代码:

    <LinearLayout 
 <span style="white-space:pre">	</span>android:background="@drawable/dailog_update"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:orientation="vertical"
        >

        <TextView
<span style="white-space:pre">	</span>    android:background="#c2c2c2"
            android:id="@+id/dialog_update_title_tv"
            android:textColor="#ffffff"
            android:textSize="18dp"
            android:layout_width="fill_parent"
            android:layout_height="40dp"
            android:gravity="center"
            android:text="版本更新" />
    </linearLayout>
dialog_update shape代码:

<shape xmlns:android="http://schemas.android.com/apk/res/android" >
      <corners android:radius="5dip" />
      <solid  android:color="#ff66ccff"/>
</shape>
由shape可以看出布局中设置background后的linearlayout的显示形状应该为:

而textview设置background后的形状为:

而textview又显示在linearlayout的上层所以导致其圆角被遮盖。


谢谢。


评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值