【问题标题】:List Image Buttons next to each other and breaks into a new line列出彼此相邻的图像按钮并换行
【发布时间】:2013-07-10 11:17:54
【问题描述】:

我想将图像按钮彼此相邻添加,一旦到达 LinearLayout 的末尾,它应该进入下一行。

注意:API 级别 10

我可能需要做什么,但我不知道怎么做:

  • 计算父宽度的末端
  • 添加按行号计算的上边距值
  • 将图像按钮设置在父级左侧

如果有更好的方法,请发表。

这是我的测试代码:

        LinearLayout layout = new LinearLayout(this);

        LinearLayout.LayoutParams paramsLO = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
        paramsLO.setMargins(0, 0, 0, 0);
        paramsLO.height = 150;
        paramsLO.width = 150;

        for (int i = 0; i < 20;i++)
        {
            ImageButton imgBtn = new ImageButton(this);
            imgBtn.setBackgroundColor(Color.TRANSPARENT);
            imgBtn.setImageResource(R.drawable.placeholder);
            imgBtn.setAdjustViewBounds(true);
            layout.addView(imgBtn,paramsLO);
        }

        layout.setGravity(Gravity.LEFT | Gravity.CENTER_HORIZONTAL);

        addContentView(layout, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));

【问题讨论】:

    标签: java android adb


    【解决方案1】:

    您是否尝试过 FlowLayout
    这里有一个不错的库flowlayout,简单好用。

    【讨论】:

      【解决方案2】:

      请查看 ApiDemos -> Animation -> LayoutAnimations。

      我认为这正是您正在寻找的。​​p>

      如果您不知道如何安装 ApiDemos,请查看这些链接。 https://stackoverflow.com/a/4467915/2538428 http://developer.android.com/tools/samples/index.html

      希望对您有所帮助...

      【讨论】:

      • 谢谢,我去看看,让你知道。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-22
      • 1970-01-01
      • 1970-01-01
      • 2011-03-08
      • 1970-01-01
      • 2018-06-20
      相关资源
      最近更新 更多