设置背景图像和XML资源 [英] set Background Image and xml Resource

查看:164
本文介绍了设置背景图像和XML资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用下面的下面的code圆RelativeLayout的的角落。我保存为 mybackground.xml 绘制文件夹。 它的正常工作四舍五入的角落,但问题是,我也想添加一个透明的图片作为我的RelativeLayout的一个背景。如何能够做到两件事?我如何使用图像和绘制XML(四舍五入角落),同时为RelativeLayout的......

 < XML版本=1.0编码=UTF-8&GT?;
<形状的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
       机器人:形状=矩形机器人:填充=10dp>
   <边角安卓bottomRightRadius =30dp
            机器人:bottomLeftRadius =30dp
            机器人:topLeftRadius =30dp
            机器人:topRightRadius =30dp/>
< /形状>
 

解决方案

您可以使用的层列表

这会是这样

 < XML版本=1.0编码=UTF-8&GT?;
<层列表的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android>
  <项目>
    <形机器人:形状=矩形机器人:填充=10dp>
    <边角安卓bottomRightRadius =30dp
             机器人:bottomLeftRadius =30dp机器人:topLeftRadius =30dp
             机器人:topRightRadius =30dp/>
    < /形状>
  < /项目>
  <项目><! - 你的透明图像 - >< /项目>
 < /层列表>
 

I am using the following below code to round the corners of RelativeLayout. I save this as mybackground.xml in drawable folder.
It's working fine for rounding the corner but the problem is that I also want to add an transparent image as a background of my RelativeLayout. How can I achieve both things? How can I use an image and a drawable xml (for rounding the corner) at the same time for a RelativeLayout ...

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
       android:shape="rectangle" android:padding="10dp">
   <corners android:bottomRightRadius="30dp"
            android:bottomLeftRadius="30dp"
            android:topLeftRadius="30dp"
            android:topRightRadius="30dp" />
</shape>

解决方案

You can use Layer-List

It will be like this

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
  <item>
    <shape android:shape="rectangle" android:padding="10dp">
    <corners android:bottomRightRadius="30dp"
             android:bottomLeftRadius="30dp" android:topLeftRadius="30dp"
             android:topRightRadius="30dp" />
    </shape>
  </item>
  <item><!-- your transparent image --></item>
 </layer-list>

这篇关于设置背景图像和XML资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆