Android的形状背景 [英] Android shape background

查看:161
本文介绍了Android的形状背景的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能绘制XML的形状,并用一个PNG为背景的形状?我已经有形状(它是带有圆角的方形),我想提出一个背景,那方。

Is it possible to draw a shape in xml, and use a png as the background to that shape? I already have the shape (it's a square with rounded corners), and i would like to put a background to that square.

推荐答案

是的,你可以使用任何形状文件作为背景的​​任何视图。此示例创建圆角背景与白色和黑色边框的形状。

Yes you can use any shape file as background for any view. This sample create rounded background with white color and black border around the shape.

示例:

rounded_corner.xml

rounded_corner.xml

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle" >

    <corners
        android:bottomLeftRadius="10dp"
        android:bottomRightRadius="10dp"
        android:topLeftRadius="10dp"
        android:topRightRadius="10dp" />

    <stroke
        android:width="0.5dp"
        android:color="@color/color_grey" />

    <solid android:color="@color/color_white" />

</shape>

ü可以用这个作为,

u can use this as,

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_gravity="center_horizontal"
    android:background="@drawable/rounded_corner"
    android:orientation="vertical" >

这篇关于Android的形状背景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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