Android   发布时间:2022-04-28  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了Android:带有两个图像的按钮|对准大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我已经以编程方式创建了此按钮,我可以使用下面的代码设置图标

Android:带有两个图像的按钮|对准

Drawable icon = context.getresources().getDrawable(iconresourcEID);
button.setCompoundDrawablesWithIntrinsicBounds(icon,null,@R_874_6633@

现在,我想在右上角有另一个图像(图标),请看下图:

Android:带有两个图像的按钮|对准

我尝试使用以下代码添加两个图像:

Drawable icon = context.getresources().getDrawable(iconresourcEID);
Drawable icon2 = context.getresources().getDrawable(iconresourceid2);
button.setCompoundDrawablesWithIntrinsicBounds(icon,icon2,@R_874_6633@

而且,我得到以下结果:

Android:带有两个图像的按钮|对准

任何人都可以告诉我,我怎样才能将它与右上角对齐?

解决方法

您的代码看起来像这样,其中btn_BACkground是您目前拥有的背景

Button button = new Button(this);
    Drawable icon = context.getresources().getDrawable(iconresourcEID);
    button.setCompoundDrawablesWithIntrinsicBounds(icon,@R_874_6633@
    button.setText("Test");

    if (hasNewupdates()) {
        button.setBACkgroundresource(R.drawable.btn_BACkground_with_icon);
    } else {
        button.setBACkgroundresource(R.drawable.btn_BACkground);
    }

这就是btn_BACkground_with_icon的样子

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://scheR_23_11845@as.android.com/apk/res/android">

    <item android:drawable="@drawable/btn_BACkground"/>
    <item android:gravity="right" android:bottom="72dp" android:drawable="@drawable/ico_info"/>
</layer-list>
@H_419_49@

大佬总结

以上是大佬教程为你收集整理的Android:带有两个图像的按钮|对准全部内容,希望文章能够帮你解决Android:带有两个图像的按钮|对准所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。