我使用了expandablelist,我想将它的页脚设置在屏幕底部,但它不起作用。我附上了代码和截图。
<ExpandableListView
android:layout_alignParentBottom="true"
android:id="@+id/list_slidermenu"
android:layout_width="260dp"
android:layout_height="fill_parent"
android:layout_gravity="start"
android:background="@color/colorAccent"
android:choiceMode="singleChoice"
android:divider="@color/colorPrimary"
android:dividerHeight="1dp"
android:groupIndicator="@null"
android:listSelector="@drawable/list_selector" >
</ExpandableListView>
expListView = (ExpandableListView) findViewById(R.id.list_slidermenu);
TextView textView = new TextView(this);
textView.setText("footer");
expListView.addFooterView(textView);
EDITTED
public class ExpandableListAdapter extends BaseExpandableListAdapter {
private Context _context;
private List<String> _listDataHeader; // header titles
// child data in format of header title, child title
private HashMap<String, List<String>> _listDataChild;
public ExpandableListAdapter(Context context,
List<String> listDataHeader,
HashMap<String, List<String>> listChildData) {
this._context = context;
this._listDataHeader = listDataHeader;
this._listDataChild = listChildData;
}
@Override
public Object getChild(int groupPosition, int childPosititon) {
return this._listDataChild.get(
this._listDataHeader.get(groupPosition))
.get(childPosititon);
}
@Override
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}
@Override
public View getChildView(int groupPosition, final int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
final String childText = (String) getChild(groupPosition,
childPosition);
if (convertView == null) {
LayoutInflater infalInflater = (LayoutInflater) this._context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(R.layout.list_item, null);
}
TextView txtListChild = (TextView) convertView
.findViewById(R.id.lblListItem);
txtListChild.setText(childText);
Drawable drawable = getDrawable(R.drawable.ic_menu_gallery);
txtListChild.setCompoundDrawablesRelativeWithIntrinsicBounds(drawable, null, null, null);
return convertView;
}
@Override
public int getChildrenCount(int groupPosition) {
return this._listDataChild.get(
this._listDataHeader.get(groupPosition)).size();
}
@Override
public Object getGroup(int groupPosition) {
return this._listDataHeader.get(groupPosition);
}
@Override
public int getGroupCount() {
return this._listDataHeader.size();
}
@Override
public long getGroupId(int groupPosition) {
return groupPosition;
}
@Override
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
String headerTitle = (String) getGroup(groupPosition);
if (convertView == null) {
LayoutInflater infalInflater = (LayoutInflater) this._context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(R.layout.list_group, null);
}
// changing the +/- on expanded list view
TextView txt_plusminus = (TextView) convertView
.findViewById(R.id.plus_txt);
if (isExpanded) {
txt_plusminus.setText("-");
Drawable plusDrawable = getDrawable(android.R.drawable.ic_menu_more);
plusDrawable.setBounds(0, 0, 0, 0); txt_plusminus.setCompoundDrawablesWithIntrinsicBounds(android.R.drawable.btn_dropdown, 0, 0, 0);
txt_plusminus.setCompoundDrawablesRelativeWithIntrinsicBounds(null, null, plusDrawable, null);
// txt_plusminus.setCompoundDrawablesRelativeWithIntrinsicBounds(null,null,plusDrawable,null);
} else {
txt_plusminus.setText("+");
}
TextView lblListHeader = (TextView) convertView
.findViewById(R.id.lblListHeader);
// lblListHeader.setTypeface(null, Typeface.BOLD);
lblListHeader.setText(headerTitle);
lblListHeader.setTextColor(getColor(R.color.black));
// nav drawer icons from resources
// navMenuIcons =
// getResources().obtainTypedArray(R.array.nav_drawer_icons);
// imgListGroup.setImageDrawable(navMenuIcons.getDrawable(groupPosition));
// adding icon to expandable list view
ImageView imgListGroup = (ImageView) convertView
.findViewById(R.id.ic_txt);
imgListGroup.setImageResource(SubMenuActivity.icon[groupPosition]);
return convertView;
}
@Override
public boolean hasStableIds() {
return false;
}
@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}
}
enter code here
答案 0 :(得分:3)
您可以使用以下代码在列表中添加页脚:
View v= inflator.inflate(R.layout.your_view, null);
expandableList.addFooterView(v);
答案 1 :(得分:0)
请看下面的代码:
公共类MainActivity扩展了AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ExpandableListView list = findViewById(R.id.list_slidermenu);
TextView v = new TextView(this);
v.setText("Footer");
list.addFooterView(v);
list.setAdapter(new ExpanadableListAdapter());
}
class ExpanadableListAdapter extends BaseExpandableListAdapter {
@Override
public int getGroupCount() {
return 0;
}
@Override
public int getChildrenCount(int groupPosition) {
return 0;
}
@Override
public Object getGroup(int groupPosition) {
return null;
}
@Override
public Object getChild(int groupPosition, int childPosition) {
return null;
}
@Override
public long getGroupId(int groupPosition) {
return 0;
}
@Override
public long getChildId(int groupPosition, int childPosition) {
return 0;
}
@Override
public boolean hasStableIds() {
return false;
}
@Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
return null;
}
@Override
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
return null;
}
@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
return false;
}
}
}