android-添加到线性布局更改中的项目间距

android-添加到线性布局更改中的项目间距,android,android-layout,android-linearlayout,Android,Android Layout,Android Linearlayout,我正在以编程方式向线性布局添加图片。此线性布局由水平滚动视图和listview项目布局的一部分包围。当我将图片与其他视图项目对齐时,它们之间的间隔正确: 但是,如果我将horizontalscrollview/linearlayout移动到其他视图项下,我会得到一些奇怪的间距,android似乎会自动这样做: 到目前为止,我已经尝试过相对性布局、嵌入线性布局、更改填充、更改边距、更改“匹配父项”、“填充父项”和“换行”内容之间的线性布局的宽度属性,但没有任何更改此间距。它总是一样的 以下是相

我正在以编程方式向线性布局添加图片。此线性布局由水平滚动视图和listview项目布局的一部分包围。当我将图片与其他视图项目对齐时,它们之间的间隔正确:

但是,如果我将horizontalscrollview/linearlayout移动到其他视图项下,我会得到一些奇怪的间距,android似乎会自动这样做:

到目前为止,我已经尝试过相对性布局、嵌入线性布局、更改填充、更改边距、更改“匹配父项”、“填充父项”和“换行”内容之间的线性布局的宽度属性,但没有任何更改此间距。它总是一样的

以下是相关代码:

LinearLayout tmpLL = (LinearLayout) convertView.findViewById(R.id.llUpgrades);

        //remove previous list contents first
        tmpLL.removeAllViews();

        for(int i = 0; i<= tmpUpgradeList.size()-1; i++){

            ImageView tmpIB = new ImageView(getContext());
            Upgrade tmpUpgrade = tmpUpgradeList.get(i);
            Upgrade.setUpgradePic(tmpIB, tmpUpgrade, tmpUpgrade.Title()==null);
            tmpIB.setTag(position + ":" + i);
            tmpIB.setPadding(5, 0, 0, 0);
            tmpIB.setMaxWidth(50);

            tmpLL.addView(tmpIB);

            tmpIB.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                      String[] split = ((String) v.getTag()).split(":");
                     runUpgradePopup(Integer.parseInt(split[0]), Integer.parseInt(split[1]));
                }
            });

            tmpIB.setOnLongClickListener(new View.OnLongClickListener() {
                @Override
                public boolean onLongClick(View v) {
                     String[] split = ((String) v.getTag()).split(":");
                     clearUpgrade(Integer.parseInt(split[0]), Integer.parseInt(split[1]));
                     return true;
                }
            });

        }
LinearLayout tmpLL=(LinearLayout)convertView.findViewById(R.id.llUpgrades);
//首先删除以前的列表内容
tmpLL.removeallview();

对于(inti=0;我花了几天时间重新编写了这个问题,但最终找到了答案。 在将图像添加到布局之前,必须添加此行

tmpIB.setAdjustViewBounds(true);

线程在这里:

尝试对滚动和线性布局的内容进行换行。nerp,尝试了滚动/换行、线性/填充和滚动/换行、线性/换行,但结果完全相同
tmpIB.setAdjustViewBounds(true);