gpt4 book ai didi

android - setCompoundDrawablePadding() 为零

转载 作者:行者123 更新时间:2023-11-30 05:12:32 25 4
gpt4 key购买 nike

我想把图片放在按钮的文字上。我想将文本和图像之间的间距设置为零。

此外,还有一个尺寸为 200 dp x 200 dp 的按钮我希望将图像和文本布置在相同的垂直填充中。请帮助我。

    Button b = findViewById(R.id.button);
Drawable d = getResources().getDrawable(R.drawable.ic_launcher_background,getTheme());

b.setCompoundDrawablesWithIntrinsicBounds(null,d,null,null);
b.setCompoundDrawablePadding(0);
b.setText("good");
b.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(MainActivity.this, "hellow", Toast.LENGTH_SHORT).show();
}
});

最佳答案

有另一种方法可以做到这一点,而且事实证明它更容易。您是否考虑过使用 TextView 并向其添加可绘制对象,而不是使用 Button 并尝试对其使用可绘制对象?它可以在您的 XML 中完成,您可以添加填充。类似的东西,

<TextView
android:id="@+id/my_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="@style/TextAppearance.AppCompat.Button"
android:textColor="@color/text_secondary_dark"
android:drawablePadding="8dp"
android:drawableTop="@drawable/my_icon"
tools:drawableTint="#000"/>

如您所见,您可以添加可绘制对象、它的填充、它的色调等。

关于android - setCompoundDrawablePadding() 为零,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53485117/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com