在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则不会出现此情况
例:
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则不会出现此情况