- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
你能帮我确定为什么小组和 child 之间有空间吗?在我的例子中,我希望所有组之间都有空格, child 应该在组的正下方没有空格(但当然是下一组的空间。我的问题是这样的:
我已将组分隔线设置为此可绘制对象 (expandable_list_group_divider):
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<size android:height="10dp"/>
</shape>
还有子分隔线(@drawable/expandable_list_child_divider):
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<size android:height="0dp"/>
</shape>
我在xml中定义了这样的布局(它是一个复合控件):
<com.jws.MyExpandableListView
android:id="@+id/expList"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:scrollbars="none"
android:divider="@drawable/expandable_list_group_divider"
android:childDivider="@drawable/expandable_list_child_divider"/>
自定义 View 类:
public class MyExpandableListView extends ExpandableListView {
protected ArrayList<Departure> departures;
public MyExpandableListView(Context context, AttributeSet attrs) {
super(context, attrs);
setGroupIndicator(null);
setChildIndicator(null);
setHorizontalFadingEdgeEnabled(true);
setVerticalFadingEdgeEnabled(true);
setFadingEdgeLength(60);
departures = new ArrayList<Departure>();
this.setAdapter(new MyExpandableListAdapter(context, this, departures));
}
}
最后是可扩展列表适配器
public class DeparturesExpandableListAdapter extends BaseExpandableListAdapter {
private final int DIVIDER_HEIGHT = 20;
private LayoutInflater inflater;
private ArrayList<Departure> departures;
private Context context;
private ExpandableListView expListView;
public DeparturesExpandableListAdapter(Context context, ExpandableListView expListView, ArrayList<Departure> departures)
{
this.context = context;
inflater = (LayoutInflater) context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
this.departures = departures;
this.expListView = expListView;
}
// This Function used to inflate parent rows view
@Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parentView)
{
final Departure departure = departures.get(groupPosition);
if(!isExpanded)
expListView.setDividerHeight(DIVIDER_HEIGHT);
else
expListView.setDividerHeight(-4);
expListView.setFooterDividersEnabled(false);
// Inflate grouprow.xml file for parent rows
convertView = inflater.inflate(R.layout.view_departure_overview, parentView, false);
//Data handling in the view...
return convertView;
}
// This Function used to inflate child rows view
@Override
public View getChildView(int groupPosition, int childPosition, boolean isLastChild,
View convertView, ViewGroup parentView)
{
final Departure departure = departures.get(groupPosition);
if(isLastChild)
expListView.setDividerHeight(DIVIDER_HEIGHT);
// Inflate childrow.xml file for child rows
convertView = inflater.inflate(R.layout.view_departure_details, parentView, false);
//Data handling...
return convertView;
}
@Override
public Object getChild(int groupPosition, int childPosition)
{
return departures.get(groupPosition);
}
//Call when child row clicked
@Override
public long getChildId(int groupPosition, int childPosition)
{
return childPosition;
}
@Override
public int getChildrenCount(int groupPosition)
{
return 1;
}
@Override
public Object getGroup(int groupPosition)
{
return departures.get(groupPosition);
}
@Override
public int getGroupCount()
{
if(departures != null)
return departures.size();
return 0;
}
//Call when parent row clicked
@Override
public long getGroupId(int groupPosition)
{
return groupPosition;
}
@Override
public void notifyDataSetChanged()
{
// Refresh List rows
super.notifyDataSetChanged();
}
@Override
public boolean isEmpty()
{
return ((departures == null) || departures.isEmpty());
}
@Override
public boolean isChildSelectable(int groupPosition, int childPosition)
{
return false;
}
@Override
public boolean hasStableIds()
{
return false;
}
@Override
public boolean areAllItemsEnabled()
{
return true;
}
}
评论图片:
最佳答案
这已经过测试并证明有效,我什至想在几个月后回到这个问题,因为没有其他方法能给我提供我想要的结果。这些显示的正是 OP(和我自己)想要的
这是我的群组或类别之类的。基本上第一个线性布局只是一个 View 的包装器,它充当类别之间的间隔,然后是另一个处理我所有格式的线性布局
在 ExpandableListView(未显示)中,我将分隔高度设置为 0。间距由 View 处理
<?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:orientation="vertical">
<View
android:layout_width="fill_parent"
android:layout_height="6dp"
android:background="@android:color/transparent"/>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="8dp"
android:background="#50601CBA">
<TextView
android:id="@+id/lblListHeader"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:textSize="17dp"
android:textColor="#FFFFFF" />
</LinearLayout>
</LinearLayout>
然后在 child 身上我有这个。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="55dip"
android:orientation="vertical" >
<TextView
android:id="@+id/lblListItem"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="12sp"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:textColor="#FFFFFF"
android:background="#50601CBA"
/>
</LinearLayout>
关于java - 如何删除 ExpandableListView 中父子之间的特定空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24955173/
我正在开发我的第一个核心数据支持的应用程序,但无法弄清楚如何正确设置 NSFetchedResultsController。我有两个实体: /-----------\ /--------
我是 javax.swing.* 包的新手,只熟悉 c#.net。我有两个 JFrame,分别是 frmLogin 和 frmMain。我想要做的只是一个像这样的简单代码: +----- C# 版本
我正在从 CoreData 迁移到 Realm...本质上我需要有两个独立的数据库,假设一个只有内存,第二个有磁盘持久性 现在在解析期间,我需要创建一个可以在给定线程中工作但与我选择的顶级 Realm
下面是我的表中的内容。 我的表格 ++++++++++++++++++++ Parent + Child ++++++++++++++++++++ C1 + G1 C1
好的,让我们设置一个场景。 场景: 您有一个内容 Controller 。该内容可能是一张照片、一篇博文等等。现在,在此内容的 html 中,您有一个 Comment Controller 。 Com
我有两个脚本 parent.sh 和 child.sh。 parent.sh 中有一个变量需要被子进程访问。我已经通过在父脚本中导出变量来实现这一点,并且该变量可用于子进程? 有什么方法可以让 chi
我见过类似但不完全相同的请求。 如果我有下表 Parent Child 1 2 1 3 4 3 5 1 6 1 5 7 8
这类似于问题 ( Finding parents in a tree hierarchy for a given child LINQ (lambda expression) )。但是,我不需要找到所
好的,所以我是 C# 做事的新手,我来自 ruby 世界。 我有一个一对多的关系(为了这个问题, parent 对 child ),出于某种原因,L2S 想要创建一个新的 parent 而不是使用
我想为我的网站创建一个完全由数据驱动的面包屑。 数据使用 MariaDB 存储,如下所示: parent_id | parent_name | child_id | child_name ——————
所以,我正在查看 Parse Anypic 教程中的代码 here 我的问题是: 有这 2 个 View Controller : @interface PAPHomeViewController :
我正在使用 CSS 处理树结构层次结构,我需要一些帮助。我想让两个父子链接起来,如果我删除字符 a,我将无法查看 CSS ::after 选择器中定义的 border-left 来自内容元素。 这是我
我对实现以下目标有点困惑1.禁用一个父div的可见性2. 但另一个代码允许子 div 可见性 http://jsfiddle.net/cbXxU/ 如果父 div 不可见或对此
我正在创建一个水平的 ul 导航栏。每个 li 元素都有不同的宽度。我想在下拉菜单中做到这一点,下拉菜单中的“子级” li 项的长度/宽度与“父级” li 项的长度/宽度相同。正在考虑使用 jQuer
我有这个问题很长时间了,我已经在网上和SO进进出出搜索,但还没有找到解决方案。我希望你能帮助我。 我有两个实体之间的父子关系,如下所示: @Entity public class Parent {
我需要在我的网页上找到一个与其他元素具有相同标签的元素,因此我需要根据子部分[parent]的标题找到xpath。 以下是网页的html代码: 基本上,我想根据上图中的 Scheduled 文本在 l
我有 2 张 table .. Adult ------------------- id ParentChild ------------------- parentID(adult's id) ch
我想创建一个函数来创建彼此具有分层关系的对象。因此,每个层对象都拥有自己的一组子层对象,并与其所有兄弟对象共享一个父对象。我不熟悉任何模式,但我想应该有一个模式可以涵盖这种情况。 //construc
我有一个父 div 和一个子 div。这里是 html Parent Child Div Js var parent = document.createElement("parent");
我正在开发一个 reactjs 应用程序 - 我正在分解一个大组件以拥有一个子组件。我在 child 中创建了一个回调函数,它将返回给 parent 。当一个复选框被选中时——子组件执行回调并返回到父
我是一名优秀的程序员,十分优秀!