mic*_*con 14 xml android shape scale
这是我想要做的:我有这个比例xml:
<?xml version="1.0" encoding="utf-8"?>
<scale xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="@drawable/mydrawable"
android:scaleGravity="bottom"
android:scaleHeight="50%" />
Run Code Online (Sandbox Code Playgroud)
我想将它与这个可绘制的xml一起使用:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient android:startColor="#FFFFFFFF"
android:endColor="#FFFF0000"
android:angle="90" />
</shape>
</item>
</layer-list>
Run Code Online (Sandbox Code Playgroud)
然后我将scale xml设置为LinearLayout的背景,但我没有看到任何内容.我错过了什么或者不可能这样做(使用XML)?
这是 ScaleDrawable 对象的问题,无法在 XML 中解决。
但这很简单,只需执行以下操作:
// Get the scale drawable from your resources
ScaleDrawable scaleDraw = (ScaleDrawable)getResources().getDrawable(R.drawable.background_scale);
// set the Level to 1 (or anything higher than 0)
scaleDraw.setLevel(1);
// Now assign the drawable where you need it
layout.setBackgroundDrawable(scaleDraw);
Run Code Online (Sandbox Code Playgroud)
我使用这个解决方案测试了你的代码,它工作得很好。
| 归档时间: |
|
| 查看次数: |
7599 次 |
| 最近记录: |