【问题标题】:It is possible to use a Shape Drawables for round corners and a 9-patch image for shadows simultaneously?可以同时对圆角使用 Shape Drawables 和对阴影使用 9-patch 图像吗?
【发布时间】:2014-01-26 19:30:17
【问题描述】:

我有一个文本视图,我希望它带有纯色黑色背景和带边框的圆角。这段代码可以正常工作。

main.xml

<RelativeLayout
        android:layout_marginTop="-20dp"
    android:layout_width="210dp"
    android:layout_height="30dp"
        android:layout_below="@id/coverflowReflect"
    android:layout_centerHorizontal="true"
        android:background="@drawable/round_corners"
    >
            <TextView
                android:layout_width="210dp"
                android:layout_height="30dp"
                android:id="@+id/statusText"
                android:textSize="16sp"
                android:gravity="center"
                android:textColor="@android:color/white" />
</RelativeLayout>

和round_corners.xml

<?xml version="1.0" encoding="UTF-8"?>
   <shape xmlns:android="http://schemas.android.com/apk/res/android">

  <solid android:color="#0101A1"/>
  <corners android:radius="4dp"/>
  <stroke android:width="2.5dip" android:color="#E27109" />
  <padding android:left="0dp" android:top="0dp" android:right="0dp"         android:bottom="0dp" /> 
   </shape> 

问题是当我想添加带有 9 补丁图像的投影时。我熟悉列表项,我可以添加另一个可绘制形状,但这不允许图像,只能作为背景颜色。

那么有什么想法可以实现吗?

谢谢。

【问题讨论】:

    标签: android xml background shadow nine-patch


    【解决方案1】:
    <layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
        <item>
          <shape 
            android:shape="rectangle">
                <stroke android:width="1dp" android:color="@color/hr_bottom" />
                <solid android:color="#00FF0000" />
                <padding android:bottom="1dp"/>
            </shape>
       </item>
    
        <item android:drawable="@drawable/decoration2">
    
       </item>
    
    </layer-list>
    

    你可以像上面那样使用layerlist。

    也可以参考这个link

    【讨论】:

      猜你喜欢
      • 2023-04-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-19
      • 1970-01-01
      • 1970-01-01
      • 2012-12-16
      • 2017-04-16
      相关资源
      最近更新 更多