首页 > 解决方案 > 根据子项动态调整布局大小

问题描述

我有一个按钮,如果按下它会显示一个带有一些数据的 ListView,问题是有时列表会像这样被裁剪出来:

在此处输入图像描述

而且我不知道如何使布局动态化,因此列表不会裁剪,这就是我所拥有的:

 pullDownArrow = (ImageView) view.findViewById(R.id.pull_down_arrow);

 topMenuLayout = (RelativeLayout) view.findViewById(R.id.menu_top);

 topMenuContainer = (LinearLayout) view.findViewById(R.id.menu_top_container);

    listView = (ListView) getView().findViewById(R.id.listview);

    final int childNum = topMenuContainer.getChildCount() + listaCuentas.size();

    final int layoutHeight = (childNum * 37 + 70);

    final ResizeAnimation[] resizeAnimation = {null};

    pullDownArrow.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {

            if (topMenuExpanded) {
                resizeAnimation[0] = new ResizeAnimation(topMenuLayout, dptopx(5));
                topMenuExpanded = false;
            } else {
                resizeAnimation[0] = new ResizeAnimation(topMenuLayout, dptopx(layoutHeight));
                topMenuExpanded = true;
            }


            resizeAnimation[0].setDuration(300);
            topMenuLayout.startAnimation(resizeAnimation[0]);

标签: androidandroid-layoutlistview

解决方案


推荐阅读