我有一个可扩展的列表视图,即viz。
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<!-- Activity Main UI -->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/darkGrey"
android:orientation="vertical">
<!-- Reusable Main Toolbar -->
<include layout="@layout/main_toolbar" />
<ExpandableListView
android:id="@+id/listview_sys_info"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/toolbar"
tools:ignore="UnknownIdInLayout">
</ExpandableListView>
</RelativeLayout>
<!-- Reusable Main Toolbar -->
<include layout="@layout/navigation_view" />
</android.support.v4.widget.DrawerLayout>
并且该组的XML信息是即
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/selector_flat_black"
android:orientation="vertical"
android:padding="15dp">
<TextView
android:id="@+id/lv_sys_gr_header"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:fontFamily="@font/roboto_medium"
android:paddingEnd="?android:attr/expandableListPreferredItemPaddingLeft"
android:paddingStart="?android:attr/expandableListPreferredItemPaddingLeft"
android:textColor="@color/lightGrey"
android:textSize="18sp" />
</LinearLayout>
问题是,与我的观点相反,这些组仅在未展开时填充屏幕空间的一部分即可。
因此,我希望可扩展列表视图组(或父项)填充UI中的可用空间,但即使经过多次尝试,我也无法实现此目的。怎么办呢?
这是适配器,以防万一:
public class SystemDetailsAdapter extends BaseExpandableListAdapter {
private Context context;
private ArrayList<DeviceInfoGroup> groups;
public SystemDetailsAdapter(Context context, ArrayList<DeviceInfoGroup> groups) {
this.context = context;
this.groups = groups;
}
@Override
public Object getChild(int groupPosition, int childPosition) {
ArrayList<DeviceInfoChild> chList = groups.get(groupPosition)
.getItems();
return chList.get(childPosition);
}
@Override
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}
@SuppressLint("InflateParams")
@Override
public View getChildView(int groupPosition, int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
DeviceInfoChild child = (DeviceInfoChild) getChild(groupPosition,
childPosition);
if (convertView == null) {
LayoutInflater layoutInflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (layoutInflater != null) {
convertView = layoutInflater.inflate(R.layout.system_info_row, null);
}
}
TextView title = null;
if (convertView != null) {
title = convertView.findViewById(R.id.row_txt_title);
}
TextView subtitle = null;
if (convertView != null) {
subtitle = convertView.findViewById(R.id.row_txt_subtitle);
}
ImageView sideIcon = null;
if (convertView != null) {
sideIcon = convertView.findViewById(R.id.row_img_left);
}
if (title != null) {
title.setText(child.getTitle());
}
if (subtitle != null) {
subtitle.setText(child.getSubtitle());
}
if (sideIcon != null) {
sideIcon.setImageResource(child.getImage());
}
return convertView;
}
@Override
public int getChildrenCount(int groupPosition) {
ArrayList<DeviceInfoChild> chList = groups.get(groupPosition)
.getItems();
return chList.size();
}
@Override
public Object getGroup(int groupPosition) {
return groups.get(groupPosition);
}
@Override
public int getGroupCount() {
return groups.size();
}
@Override
public long getGroupId(int groupPosition) {
return groupPosition;
}
@SuppressLint("InflateParams")
@Override
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
DeviceInfoGroup group = (DeviceInfoGroup) getGroup(groupPosition);
if (convertView == null) {
LayoutInflater inf = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (inf != null) {
convertView = inf.inflate(R.layout.system_info_group, null);
}
}
TextView tv = null;
if (convertView != null) {
tv = convertView.findViewById(R.id.lv_sys_gr_header);
}
if (tv != null) {
tv.setText(group.getName());
}
return convertView;
}
@Override
public boolean hasStableIds() {
return true;
}
@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}
}
答案 0 :(得分:0)
好的,所以我设法做到如下:
convertView.setLayoutParams(new ViewGroup.LayoutParams(parent.getWidth(), parent.getHeight() / 7));