Android Layer-List VectorDrawable大小

时间:2015-11-06 22:41:46

标签: android background layer-list android-vectordrawable

我的问题与此问题有关:link。我最近将用于Android的大部分资源从用于不同分辨率的不同png文件更改为矢量绘图。我正在使用"swipe-to-delete" library可以在滑动期间更改其视图的背景,以显示带有垃圾桶图标的Gmail风格红色背景,类似于此(具有带检查图标的绿色背景):

enter image description here

我曾经使用以下代码执行此操作,而我仍然使用< API 21

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <color android:color="@color/accent"/>
    </item>
    <item android:right="@dimen/activity_horizontal_margin">
        <bitmap
            android:gravity="right|center_vertical"
            android:src="@drawable/ic_delete_24dp"/>
    </item>
</layer-list>

但是,API 21 +

需要不同的语法
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <color android:color="@color/accent" />
    </item>
    <item android:right="@dimen/activity_horizontal_margin"
          android:drawable="@drawable/ic_delete_24dp"
          android:gravity="right|center_vertical"/>
</layer-list>

现在,不是左/右侧的图标,而是API 21上的图标&amp; API 22(Lollipop)被拉伸以填满屏幕。有没有办法指定图标的宽度?

1 个答案:

答案 0 :(得分:0)

将此添加到您的应用级build.gradle文件

[HttpPost]
public ActionResult DoSomething(PostViewModel model)
{
    //////////////////////////
    /*
        * The code in this section should run asynchronously (in another thread I guess).
        * That means the UI should not wait for any of these operations to end.
        * 
        * */
    ComputeHeavyOperations();
    //////////////////////////


    //the response should be returned immediatelly 
    return Json("Heavy operations have been triggered.");
}

private void ComputeHeavyOperations()
{
    //execute some heavy operations; like encoding a video 
}