Android 使ExpandableListView尊重项目边距和填充
我有一个ExpandableListView,我正在填充项目。我希望标题(这里是“肉”)比列表项宽 但是,ExpandableListView似乎不尊重XML中定义的边距/填充,也不尊重项目的编程设置填充。它确实修改了父项(“meat”),但相同的代码不适用于项目 我该怎么做 以下是我的自定义适配器的相关部分:Android 使ExpandableListView尊重项目边距和填充,android,expandablelistview,expandablelistadapter,Android,Expandablelistview,Expandablelistadapter,我有一个ExpandableListView,我正在填充项目。我希望标题(这里是“肉”)比列表项宽 但是,ExpandableListView似乎不尊重XML中定义的边距/填充,也不尊重项目的编程设置填充。它确实修改了父项(“meat”),但相同的代码不适用于项目 我该怎么做 以下是我的自定义适配器的相关部分: @Override public View getGroupView(int position, boolean isExpanded, View view, ViewGroup
@Override
public View getGroupView(int position, boolean isExpanded, View view, ViewGroup parent) {
if (view == null) {
LayoutInflater layoutInflater = (LayoutInflater) this.context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = layoutInflater.inflate(R.layout.list_category, null);
}
view.setPadding(10, 0, 10, 0); //RESPECTED
initializeGroupComponents(view, getGroup(position));
return view;
}
@Override
public View getChildView(int position, int expandedPosition, boolean isLastChild, View view, ViewGroup parent) {
if (view == null) {
LayoutInflater layoutInflater = (LayoutInflater) this.context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = layoutInflater.inflate(R.layout.list_ingredient, parent, false);
}
view.setPadding(10, 2, 10, 2); //DOES NOT WORK
initializeChildComponents(view, getChild(position, expandedPosition));
return view;
}
我的XML的相关部分:
工作组:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout_categoryContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="2dp"
android:orientation="vertical">
该项目:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/row"
android:layout_width="match_parent"
android:layout_height="62dp"
android:layout_marginBottom="1dp"
android:layout_marginEnd="6dp"
android:layout_marginStart="6dp"
android:background="@android:color/white"
android:gravity="center_vertical"
android:orientation="horizontal"
android:padding="10dp">
为页眉添加一个额外的布局并添加边距
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout_categoryContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_marginTop="5dp"
android:layout_marginEnd="5dp"
android:layout_marginStart="5dp">
//other content
</LinearLayout>
</LinearLayout>
//其他内容
为页眉添加一个额外的布局并添加边距
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout_categoryContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_marginTop="5dp"
android:layout_marginEnd="5dp"
android:layout_marginStart="5dp">
//other content
</LinearLayout>
</LinearLayout>
//其他内容
完美!非常感谢。完美的非常感谢。