Android 如何降低listview项的高度
我有一个可扩展的列表视图。这些行由textview和自定义复选框组成。复选框的大小取决于textview的文本大小。只有两种尺寸。当显示“大”复选框时,行之间的差异很小。当显示“小”复选框时,它看起来很大。如何减少行与行之间的行高度Android 如何降低listview项的高度,android,Android,我有一个可扩展的列表视图。这些行由textview和自定义复选框组成。复选框的大小取决于textview的文本大小。只有两种尺寸。当显示“大”复选框时,行之间的差异很小。当显示“小”复选框时,它看起来很大。如何减少行与行之间的行高度 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:la
<?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:id="@+id/childlayout"
android:orientation="vertical">
<RelativeLayout
android:id="@+id/relativeLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_centerVertical="true"
android:layout_height="wrap_content"
android:layout_marginLeft="50dp" >
<TextView
android:id="@+id/child_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:gravity="center_vertical"
android:textColor="#000000"/>
</LinearLayout>
<CheckBox
android:id="@+id/multiple_checkbox"
android:layout_width="wrap_content"
android:layout_centerVertical="true"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:checked="true"
android:layout_marginRight="10dp"
android:button="@drawable/productlists_custom_cb"
android:clickable="false"
android:focusable="false"
android:focusableInTouchMode="false" />
</RelativeLayout>
</LinearLayout>
如果我将相对布局的布局高度设置为30dp,行高度将更小。但不应该是这样
这是用于打开和关闭较小复选框的.xml:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true" android:drawable="@drawable/cbon348" />
<item android:state_checked="false" android:drawable="@drawable/cboff348" />
</selector>
有人可能会认为图像的画布比图像本身大得多,但我向你保证,事实并非如此
编辑:
我将代码简化为如下所示,但仍然没有任何内容:
<?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:id="@+id/childlayout"
android:orientation="horizontal">
<TextView
android:id="@+id/child_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="50dp"
android:gravity="center_vertical"
android:textColor="#000000"/>
<CheckBox
android:id="@+id/multiple_checkbox"
android:layout_width="wrap_content"
android:layout_gravity="center_vertical"
android:gravity="center_vertical"
android:layout_height="wrap_content"
android:checked="true"
android:layout_marginRight="10dp"
android:button="@drawable/productlists_custom_cb"
android:clickable="false"
android:focusable="false"
android:focusableInTouchMode="false" />
</LinearLayout>
尝试在文本视图上使用负数填充以减少空间
android:paddingTop="-5dp"
android:paddingBottom="-5dp"
我的解决方案是创建不同大小的复选框图像,然后根据屏幕大小设置适当的图像:
if ((getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_LARGE)
{
holder.checkBox.setButtonDrawable(R.drawable.productlists_custom_cb48);
}
else if ((getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_NORMAL)
{
holder.checkBox.setButtonDrawable(R.drawable.productlists_custom_cb48);
}
else if ((getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_SMALL)
{
holder.checkBox.setButtonDrawable(R.drawable.productlists_custom_cb36);
}
holder.checkBox.setLayoutParams(new android.widget.RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, GetDipsFromPixel(20)));
可能重复:这也适用于原始大小,使复选框相互重叠或太近。我不明白,您的状态列表没有更改文本大小,因此它必须是两个单独的列表。只需有两个单独的行布局。一个对较小的文本进行填充调整,另一个对较大的文本不进行填充调整。