Android的层列表不显示比例绘制项目? [英] Android layer-list does not show scale drawable item?
问题描述
使用下面的图层列表,我的尺度绘制从未显示。这是为什么?
menu_dialog_header.xml
<?XML版本=1.0编码=UTF-8&GT?;
<层列表的xmlns:机器人=http://schemas.android.com/apk/res/android>
<项目>
<形状和GT;
[固体机器人:色=@彩色/黑白>< /固体>
< /形状>
< /项目>
<项目>
<规模
机器人:scaleHeight =50%
机器人:scaleWidth =100%
机器人:scaleGravity =顶
机器人:可绘制=@绘制/闪耀/>
< /项目>
< /层列表>
shine.xml
<?XML版本=1.0编码=UTF-8&GT?;
<形状
的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:形状=矩形>
[固体机器人:色=@色/闪耀/>
< /形状>
menu_dialog.xml
<! - 标题 - >
<的LinearLayout
机器人:背景=@绘制/ menu_dialog_header
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
机器人:重力=CENTER_HORIZONTAL |中心
机器人:填充=8DP
机器人:方向=横向>
...
在情况下,其他人在此页由knowledeable谷歌的引导下降...
我有一个解决办法,可能会或可能不会为你工作:而不是使用<项目建设规模及GT;
尝试<&插图GT;
。您可以使用℃的组合;项目>的
的android:顶部
/ 的android :底部
/ 的android:左
/ 的android:权
和<&插图GT;
的Android:insetXXX尺寸图像
您可以做的事情一样设置每个插入值相对的两侧到源图像的尺寸。例如,如果你有一个64像素宽的形象,希望通过削减50%下来,你可以为每边做(64/4 = 16)
Using the layer-list below, my scale drawable is never shown. Why is that?
menu_dialog_header.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape>
<solid android:color="@color/black"></solid>
</shape>
</item>
<item>
<scale
android:scaleHeight="50%"
android:scaleWidth="100%"
android:scaleGravity="top"
android:drawable="@drawable/shine" />
</item>
</layer-list>
shine.xml
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@color/shine" />
</shape>
menu_dialog.xml
<!-- header -->
<LinearLayout
android:background="@drawable/menu_dialog_header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal|center"
android:padding="8dp"
android:orientation="horizontal" >
...
In case another person descends upon this page by the guiding of the knowledeable Google...
I have a workaround that may or may not work for you: instead of using <scale>
, try <inset>
. You can use a combination of the <item>
's android:top
/ android:bottom
/ android:left
/ android:right
and the <inset>
's android:insetXXX to size the image
You can do things like set the sides of each inset value relative to your source image's dimensions. For example, if you have a 64 pixel-wide image and want to cut it down by 50%, you can do (64 / 4 = 16) for each side
这篇关于Android的层列表不显示比例绘制项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!