Android setCompoundDrawablesWithIntrinsicBounds手工设置文本与图片相对位置说明

本文介绍如何在Android中使用setCompoundDrawablesWithIntrinsicBounds方法手工设置文本与图片的相对位置。通过具体示例展示了该方法如何实现类似XML布局文件中定义的图文混排效果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Android setCompoundDrawablesWithIntrinsicBounds手工设置文本与图片相对位置说明

setCompoundDrawablesWithIntrinsicBounds(left, top, right, bottom)意思是设置Drawable显示在text的左、上、右、下位置(Textview、Button都以),作用效果和以下的xml布局中绿色背景那行代码一样,两个结合使用可以对图片进行变化

 

XML文件布局:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <TextView
        android:id="@+id/btn1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:drawableTop="@drawable/t1"
        android:text="tete"
        />
</LinearLayout>

 

转载于:https://www.cnblogs.com/lyd447113735/p/8202719.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值