如何指定宽度的绘制项目,并高度 [英] how to specify width and height of a drawable item

查看:88
本文介绍了如何指定宽度的绘制项目,并高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

喜是提供宽度drawable.xml在绘制文件夹中定义的绘制和高度的反正。

例如:

 <选择的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android>
     <项目的android:STATE_ pressed =真
           机器人:可绘制=@可绘制/ button_ pressed/> <  - !pressed  - >
     <项目安卓state_focused =真
           机器人:可绘制=@可绘制/ button_focused/> <! - 集中 - >
     <项目机器人:可绘制=@可绘制/ button_normal/> <! - 默认 - >
 < /选择器>
 

我想指定的宽度和高度可能在某种程度上使用比例标签里面,我试过但是很奏效。这是我的code:

 <选择的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android>
    <项目机器人:可绘制=@可绘制/ icon_ratingstar>
        <规模安卓scaleWidth =20机器人:scaleHeight =20机器人:可绘制=@可绘制/ icon_ratingstar/>
    < /项目>
< /选择器>
 

项目> 标签宽度解决方案

您可以在&LT指定code>和高度绘制

 <选择的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android>
 <项目的android:STATE_ pressed =真
       机器人:宽=100dp
       机器人:身高=20dp
       机器人:可绘制=@可绘制/ button_ pressed/> <  - !pressed  - >
 <项目安卓state_focused =真
       机器人:宽=100dp
       机器人:身高=20dp
       机器人:可绘制=@可绘制/ button_focused/> <! - 集中 - >
 <项目机器人:可绘制=@可绘制/ button_normal/> <! - 默认 - >
 

Hi is there anyway of providing width and height of a drawable defined in drawable.xml in drawable folder.

Example:

 <selector xmlns:android="http://schemas.android.com/apk/res/android">
     <item android:state_pressed="true"
           android:drawable="@drawable/button_pressed" /> <!-- pressed -->
     <item android:state_focused="true"
           android:drawable="@drawable/button_focused" /> <!-- focused -->
     <item android:drawable="@drawable/button_normal" /> <!-- default -->
 </selector>

I wanted to specify width and height maybe somehow using "scale" tag inside it which i tried but didnt worked. This is my code:

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/icon_ratingstar">
        <scale android:scaleWidth="20" android:scaleHeight="20" android:drawable="@drawable/icon_ratingstar" />
    </item>
</selector>

解决方案

You can specify inside the <item> tag the width and height of the drawable:

<selector xmlns:android="http://schemas.android.com/apk/res/android">
 <item android:state_pressed="true"
       android:width="100dp"
       android:height="20dp"
       android:drawable="@drawable/button_pressed" /> <!-- pressed -->
 <item android:state_focused="true"
       android:width="100dp"
       android:height="20dp"
       android:drawable="@drawable/button_focused" /> <!-- focused -->
 <item android:drawable="@drawable/button_normal" /> <!-- default -->

这篇关于如何指定宽度的绘制项目,并高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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