ListView 单行太高 压缩背景图大小

在ListView的某一行中 如果布局的9.png背景高度太大,但我们又不想修改该9.PNG图片,此时需要让ANROID自动压缩9.PNG图片,可以设置布局的padding来自动压缩9.PNG图片。
例:
list_item.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/grid_divi_bar"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/grid_label_name"
android:text="Short"
android:textSize="12dp"
android:textColor="#4C4C4A"
/>
</LinearLayout>
如果此background图片太高,则我们需要添加android:padding="1"
或者在程序中设置padding = 1 view.setPadding(1);
这样图片就被压缩到合适的尺寸了


如果在ListView 的item中如果存在多个LinearLayout
此时如果我们使用setBackgroudDrawable()来设置背景图,则有可能造成LinearLayout之间存在白色间隙,如果使用setBackgroundResource则不会出现此情况
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值