我使用FlexibleAdapter的库 我有3个标题和3个SectionItems, 我需要为这些部分项目实现一个库:Slice 要在每个SectionItems上显示Radius角,
但是半径仅归因于第一部分,我不知道或者是问题。我无法获得其他部分的圆角。
public class SectionItem extends AbstractSectionableItem<SectionItem.DataCellViewHolder,HeaderItem> {
public static String NAME = SectionItem.class.getName();
public class DataCellViewHolder extends FlexibleViewHolder implements DataCellViewHolder2 {
FrameLayout frame;
TextView title;
DataCellViewHolder(View itemView, FlexibleAdapter adapter) {
super(itemView, adapter);
frame = (FrameLayout)itemView.findViewById(R.id.frame);
title = (TextView) itemView.findViewById(R.id.title);
}
@Override
public FrameLayout getFrame() {
return frame;
}
@Override
public int getItemCount() {
mAdapter.getSectionItems(getHeader()).size();
}
@Override
public int getItemViewType(int position) {
if (position==1){
return VIEW_TYPE_TOP;
} else if (position == getItemCount()) {
return VIEW_TYPE_BOTTOM;
} else {
return VIEW_TYPE_CENTER;
}
}
}
private String title;
public SectionItem(String title, HeaderItem header) {
super(header);
this.title = title;
setDraggable(true);
}
public String getTitle() {
return title;
}
@Override
public HeaderItem getHeader() {
return super.getHeader();
}
public void setTitle(String title) {
this.title = title;
}
@Override
public void bindViewHolder( FlexibleAdapter adapter, DataCellViewHolder holder, int position, List payloads) {
holder.title.setText(title);
Slice slice = new Slice(holder.getFrame());
slice.setElevation(2.0f);
int view = holder.getItemViewType(position);
if (view == VIEW_TYPE_TOP) {
slice.setRadius(8.0f);
slice.showLeftTopRect(false);
slice.showRightTopRect(false);
slice.showRightBottomRect(true);
slice.showLeftBottomRect(true);
slice.showTopEdgeShadow(true);
slice.showBottomEdgeShadow(false);
} else if (view == VIEW_TYPE_BOTTOM) {
slice.setRadius(8.0f);
slice.showLeftTopRect(true);
slice.showRightTopRect(true);
slice.showRightBottomRect(false);
slice.showLeftBottomRect(false);
slice.showTopEdgeShadow(false);
slice.showBottomEdgeShadow(true);
} else {
slice.setRadius(0.0f);
slice.showTopEdgeShadow(false);
slice.showBottomEdgeShadow(false);
}
}
@Override
public boolean equals(Object inObject) {
if (inObject instanceof SectionItem) {
SectionItem inItem = (SectionItem) inObject;
return this.title.equals(inItem.title);
}
return false;
}
@Override
public int getLayoutRes() {
return R.layout.item_center;
}
@Override
public DataCellViewHolder createViewHolder(View view, FlexibleAdapter adapter) {
Log.w(NAME, " : createViewHolder");
return new DataCellViewHolder(view, adapter);
}
}
main.xml中
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#3be13e"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="10dp"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context="com.ahmed.flexibleadapterdemo.MainActivity">
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</FrameLayout>
item_center.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/plus_sign">
<FrameLayout
android:id="@+id/frame"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/white"
android:layout_marginTop="0dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginEnd="0dp"
android:clickable="true">
<TextView
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="30dp"
android:layout_margin="0dp" />
</FrameLayout>
</FrameLayout>
答案 0 :(得分:0)
我不知道FlexibleAdapter是如何工作的,所以我建议使用attr:background和您的视图&#34; R.id.frame&#34;制作半径;
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="8dp"/>
<solid android:color="@color/color_bg"/>
</shape>