里面shapes.xml在安卓多发性形状 [英] Multipe shapes inside shapes.xml in android

查看:109
本文介绍了里面shapes.xml在安卓多发性形状的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找机会,以确定不同形状的单一shapes.xml内,是指每个人在某些特定事件。

最后,我已经找到了解决我的问题。和答案是使用电平的列表。

 < XML版本=1.0编码=UTF-8&GT?;
<电平表的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android>
<项目安卓maxLevel =0>
    <形状的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
        机器人:形状=矩形>
        
        <梯度安卓startColor =#AAA
            机器人:endColor =#EEE机器人:角=270/>
        
        <边角安卓bottomRightRadius =7DP
            机器人:bottomLeftRadius =7DP机器人:topLeftRadius =7DP
            机器人:topRightRadius =7DP/>
    < /形状>

< /项目>
<项目安卓maxLevel =1>
    <形状的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
        机器人:形状=椭圆形>
        
        <梯度安卓startColor =#EEE机器人:centerColor =#DDD
            机器人:endColor =#00fff2机器人:角=270/>
        
        <边角安卓bottomRightRadius =7DP
            机器人:bottomLeftRadius =7DP机器人:topLeftRadius =7DP
            机器人:topRightRadius =7DP/>
    < /形状>
< /项目>
< /电平列表>
 

将此运用到样式背景属性。的型动物形状的交换可以由电平设置到该元素来实现。

例如: findViewById(R.id.mybutton).getBackground()执行setLevel(1);

在上面的code,我的第二个形状设置按钮id为myButton的。

解决方案

 < XML版本=1.0编码=UTF-8&GT?;
<形状
    的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android>
    <行程机器人:宽=1dip机器人:颜色=#FF8000/>
    [固体
        机器人:颜色=#00FFFFFF
        机器人:以下属性来=10dip
        机器人:paddingTop =10dip/>
    <边角机器人:半径=10px的/>

    <填充
        机器人:左=10dip
        机器人:顶部=10dip
        机器人:右=10dip
        机器人:底部=10dip/>
< /形状>
 

您可以使用此为寄宿生和任意形状..its仅供参考...... 如果它是有用的,以便接受的答案,投票最多的答案

I have been searching for possibilities to define different shapes inside a single shapes.xml and refer to each one on some specific events.

At last I've found a solution to my question. And the answer is using level-list.

<?xml version="1.0" encoding="utf-8"?>
<level-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:maxLevel="0">
    <shape xmlns:android="http://schemas.android.com/apk/res/android"
        android:shape="rectangle">
          
        <gradient android:startColor="#aaa" 
            android:endColor="#eee" android:angle="270" />
           
        <corners android:bottomRightRadius="7dp"
            android:bottomLeftRadius="7dp" android:topLeftRadius="7dp"
            android:topRightRadius="7dp" />
    </shape>

</item>
<item android:maxLevel="1">
    <shape xmlns:android="http://schemas.android.com/apk/res/android"
        android:shape="oval">
          
        <gradient android:startColor="#eee" android:centerColor="#ddd"
            android:endColor="#00fff2" android:angle="270" />
           
        <corners android:bottomRightRadius="7dp"
            android:bottomLeftRadius="7dp" android:topLeftRadius="7dp"
            android:topRightRadius="7dp" />
    </shape>
</item>
</level-list>

Apply this to the background attribute in the style. the Interchanging of differents shapes can be achieved by setting the level to that element.

Eg: findViewById(R.id.mybutton).getBackground().setLevel(1);

In the above code I'm setting the second shape to the button with id mybutton.

解决方案

<?xml version="1.0" encoding="UTF-8"?>
<shape 
    xmlns:android="http://schemas.android.com/apk/res/android">
    <stroke android:width="1dip" android:color="#FF8000" />
    <solid 
        android:color="#00FFFFFF"
        android:paddingLeft="10dip"
        android:paddingTop="10dip"/>
    <corners android:radius="10px"/>

    <padding 
        android:left="10dip" 
        android:top="10dip" 
        android:right="10dip" 
        android:bottom="10dip" /> 
</shape>

you can use this for Boarder and any shape ..its for reference...'' If it is useful so accept the answer and vote up the answer

这篇关于里面shapes.xml在安卓多发性形状的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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