【问题标题】:Android Clip Sub ViewAndroid 剪辑子视图
【发布时间】:2012-07-15 19:28:09
【问题描述】:

我有一个线性布局和一个图像视图。线性布局具有圆角。我希望我的图像位于视图的最顶部,但是当图像出现时,角不再是圆形的。我能为此做些什么?我知道在 iOS 中有一个用于容器(UIView)的剪辑子视图选项。但不确定是否适用于 Android。

 <LinearLayout   xmlns:android="http://schemas.android.com/apk/res/android"   
    android:orientation="vertical"
    android:gravity="top"
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"  
    android:background="@drawable/cell_rounded_edges">  
    <ImageView
        android:id="@+id/prodImage"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="top"
        android:gravity="top"   
        android:focusable="false"
        android:clickable="false"   
        android:adjustViewBounds="true"       
        />
.....and so on

【问题讨论】:

标签: android imageview android-linearlayout


【解决方案1】:

任何ViewGroup(包括LinearLayout)都具有android:clipChildren 的布尔XML 属性(也可以通过setClipChildren(boolean) 以编程方式设置),但根据文档,默认情况下设置为true。

【讨论】:

    【解决方案2】:

    我找到了一个非常简单的解决方案!

    我的布局顶部有一个图像,其中只有顶角必须是圆形的(在 iOS 中模拟剪辑到子视图),因为我的图层的所有角都是圆形的。

    在我的图片背景上:

    <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android" >
    <solid android:color="#e3e3e3"/>
    <corners android:bottomRightRadius="0dip"
             android:bottomLeftRadius="0dip"
             android:topLeftRadius="25dip"
             android:topRightRadius="25dip"/>
    <padding android:left="0dip" android:top="0dip" android:right="0dip" android:bottom="0dip" />
    </shape>
    

    在我的图层背景上:

    <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android" >
    <solid android:color="#FFF"/>
    <corners android:radius="25dip"/>
    <padding android:left="0dip" android:top="0dip" android:right="0dip" android:bottom="0dip" /> 
    </shape>
    

    【讨论】:

      猜你喜欢
      • 2011-07-31
      • 1970-01-01
      • 2010-11-22
      • 1970-01-01
      • 2015-04-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-17
      相关资源
      最近更新 更多