Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/grails/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
android如何在Expandablelistview的页脚中央制作一个按钮_Android_Android Layout_Android Xml - Fatal编程技术网

android如何在Expandablelistview的页脚中央制作一个按钮

android如何在Expandablelistview的页脚中央制作一个按钮,android,android-layout,android-xml,Android,Android Layout,Android Xml,因为ExpandableListView没有内置页脚,所以我自己构建了它,我在上面加了一个按钮。我试着把这个按钮放在页脚的中央 页脚所有地址组页脚.xml 在上面的代码中,convertView是包含页脚的视图。 在TRUEif语句中,正在添加页脚 请问我做错了什么?如何制作中间的按钮 谢谢 评论之后 安瑟尔之后 您需要为视图设置布局参数: LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams( Li

因为
ExpandableListView
没有内置页脚,所以我自己构建了它,我在上面加了一个按钮。我试着把这个按钮放在页脚的中央

页脚所有地址组页脚.xml 在上面的代码中,
convertView
是包含页脚的视图。 在
TRUE
if语句中,正在添加页脚

请问我做错了什么?如何制作中间的按钮

谢谢

评论之后

安瑟尔之后
您需要为视图设置
布局参数

LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
   LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
convertView.setLayoutParams(layoutParams);

我自己找到了解决方案,在利用了
hierarchyviewer
工具之后,解决方案是将expandablelistview的宽度设置为
fill parent



尝试不使用
线性布局包装按钮。使用
HeirarchyViewer
查看实时布局会有很大帮助。@User117仍然没有居中使用
HeirarchyViewer
工具查看在运行时该项目使用的布局。不知道您也在编程,除了足球;) 当我添加你的代码时,我得到了这个例外

02-12 18:00:04.751:E/AndroidRuntime(317):致命异常:main 02-12 18:00:04.751:E/AndroidRuntime(317):java.lang.ClassCastException:android.widget.LinearLayout$LayoutParams 02-12 18:00:04.751:E/AndroidRuntime(317):在android.widget.ListView.ListView.measuresrapchild(ListView.java:1117)您的
列表视图在哪种布局中?使用那种类型的参数。我使用的是ExpandableListview而不是Listview,我编辑了我的问题并向您添加了xml,您是否可以检查
所有地址\u组\u页脚。xml
请,我已经阅读了按钮的布局我找到了解决方案并将其作为答案写下来,非常感谢,+1谢谢您
@Override
    public View getChildView(int groupPosition, int childPosition,
            boolean isLastChild, View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub
        AllAddressChild child = (AllAddressChild) getChild(groupPosition,
                childPosition);
        if (childPosition == groups.get(groupPosition).getChilds().size() - 1) {
            // if (convertView == null) {
            LayoutInflater infalInflater = (LayoutInflater) context
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = infalInflater.inflate(
                    R.layout.all_addresses_group_footer, null);
            // }
            Button b_edit = (Button) convertView
                    .findViewById(R.id.b_all_addresses_group_footer_edit);
            b_edit.setText("Edit");
            b_edit.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    // TODO Auto-generated method stub
                    Intent intent = new Intent(context, EditAddress.class);
                    ((Activity) context).startActivityForResult(intent, 104);
                }
            });
            convertView.setPadding(0, 0, 0, 20);
            return convertView;
        } else { another code
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#FFFFFF"
    android:orientation="vertical" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginBottom="25dip"
        android:layout_marginTop="20dip"
        android:text="@string/tv_allAddresses"
        android:textColor="#025f7c"
        android:textSize="25dip"
        android:typeface="serif" />

    <ExpandableListView
        android:id="@+id/elv_all_addresses_addresses"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:cacheColorHint="#00000000"
        android:padding="10dip" >
    </ExpandableListView>

    <Button
        android:id="@+id/b_all_addresses_addAddress"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:background="@drawable/button_selector"
        android:paddingTop="20dip"
        android:text="@string/b_addAddress"
        android:paddingRight="5dip"
        android:paddingLeft="5dip"
        android:textColor="#FFFFFF" />

</LinearLayout>
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
   LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
convertView.setLayoutParams(layoutParams);
<ExpandableListView
        android:id="@+id/elv_all_addresses_addresses"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:cacheColorHint="#00000000"
        android:padding="10dip" >
    </ExpandableListView>