我正在使用 ExpandableList ,我希望在展开时在列表上以及组和子视图之间放置一个按钮(或图像)。
我也在用 BaseExpandableListAdapter 在我的适配器
我的代码就像这样
@Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
final Context context = parent.getContext();
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (convertView == null) {
convertView = inflater.inflate(R.layout.item_lesson_list, parent, false);
mGroupViewHolder = new GroupViewHolder();
mGroupViewHolder.indicatorIV = (IndicatorView)convertView.findViewById(R.id.indicator);
mGroupViewHolder.titleTV = (TextView)convertView.findViewById(R.id.title);
mGroupViewHolder.subtitleTV = (TextView)convertView.findViewById(R.id.subtitle);
mGroupViewHolder.homeworkRateView = (CircleProgressView)convertView.findViewById(R.id.homework_rate);
mGroupViewHolder.header = (LinearLayout) convertView.findViewById(R.id.header);
mGroupViewHolder.headerTitle = (TextView) convertView.findViewById(R.id.list_header_tv);
convertView.setTag(mGroupViewHolder);
} else {
mGroupViewHolder = (GroupViewHolder)convertView.getTag();
}
if (isExpanded) {
mGroupViewHolder.indicatorIV.setState(IndicatorView.STATE_ON);
} else {
mGroupViewHolder.indicatorIV.setState(IndicatorView.STATE_OFF);
}
Lesson lesson = mGroupList.get(groupPosition);
LessonDatum lessonDatum = lesson.lessonData.get(0);
mGroupViewHolder.homeworkRateView.setProgress(lessonDatum.homeworkRate / 100.0f);
mGroupViewHolder.homeworkRateView.setText(lessonDatum.homeworkRate + "%");
return convertView;
}
@Override
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
final Context context = parent.getContext();
Lesson lesson = mGroupList.get(groupPosition);
LessonDatum lessonDatum = lesson.lessonData.get(0);
if (convertView == null) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.content_lesson_list, null);
mChildViewHolder = new ChildViewHolder();
mChildViewHolder.chapterLV = (ExpandedListView) convertView.findViewById(R.id.chapterListView);
mChildViewHolder.homeworkLV = (ExpandedListView) convertView.findViewById(R.id.homeworkListView);
mChildViewHolder.homeworkProgressTV = (TextView) convertView.findViewById(R.id.homework_progress_tv);
mChildViewHolder.homeworkProgressBar = (ProgressBar) convertView.findViewById(R.id.homework_progress_bar);
convertView.setTag(mChildViewHolder);
} else {
mChildViewHolder = (ChildViewHolder)convertView.getTag();
}
int homeworkRate = lessonDatum.homeworkRate;
mChildViewHolder.homeworkProgressTV.setText(homeworkRate+"%");
mChildViewHolder.homeworkProgressBar.setProgress(homeworkRate);
final ArrayList<String> chapterList = new ArrayList<>(lessonDatum.chapters.size());
for (Chapter c : lessonDatum.chapters) chapterList.add(c.content);
ArrayAdapter<String> chapterAdapter = new ArrayAdapter<>(context, android.R.layout.simple_list_item_1, chapterList);
mChildViewHolder.chapterLV.setAdapter(chapterAdapter);
final ArrayList<String> homeworkList = new ArrayList<>(lessonDatum.homeworks.size());
for (Homework h : lessonDatum.homeworks) homeworkList.add(h.content);
ArrayAdapter<String> homeworkAdapter = new ArrayAdapter<>(context, android.R.layout.simple_list_item_1, homeworkList);
mChildViewHolder.homeworkLV.setAdapter(homeworkAdapter);
final ClipboardManager clipboardManager = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
mChildViewHolder.homeworkLV.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
CharSequence charSequence = homeworkList.get(position);
ClipData clipData = ClipData.newPlainText("LABEL",charSequence);
clipboardManager.setPrimaryClip(clipData);
}
});
mChildViewHolder.chapterLV.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
CharSequence charSequence = chapterList.get(position);
ClipData clipData = ClipData.newPlainText("LABEL", charSequence);
clipboardManager.setPrimaryClip(clipData);
}
});
return convertView;
}
当我想到android L中的“浮动动作按钮”时,您可以轻松想象该视图。
请帮助!
答案 0 :(得分:0)
我用这种方式解决了这个问题
在我的xml中添加 android:clipChildren =“false”就像一个魅力 我把它放在像这样的上边缘
<ImageView
android:clipChildren="false"
android:layout_marginTop="-12dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/abc_btn_check_material"/>
我必须做的另外一点是在父视图中放置 android:clipChildren =“false”。
自我解决了。 很遗憾,由于没有声誉,我无法发布图片以帮助理解。