【问题标题】:Remove Android button without changing other buttons' layout删除 Android 按钮而不更改其他按钮的布局
【发布时间】:2013-01-05 04:26:04
【问题描述】:

如何在调用 removeView 方法时禁用按钮的偏移量? 当我按下删除按钮时

我得到:

我需要:

我能做到吗? 如果可以,怎么做。 如果没有,我可以做什么。


我只需要删除按钮,因为我在相同位置添加了一个新按钮。

但是当我使用 removeView 删除按钮时,例如删除 Button0,我的按钮 Button1、Button2、Button3 向左移动。移除 Button0

后,我需要将按钮置于其位置

【问题讨论】:

  • button.setVisibility(View.INVISIBLE);

标签: android android-layout android-widget


【解决方案1】:

使用

button1.setVisibility(View.INVISIBLE);

【讨论】:

    【解决方案2】:

    尝试:

    private void removeView() {
    linearLayout = (LinearLayout) findViewById(R.id.linearlayout);
    int count = linearLayout.getChildCount();
    if (count - 2 > 0) {
    linearLayout.removeViewAt(count - 2);
    }
    }
    

    编辑: 或者您可以从布局中按 id 重新设置按钮:

    private void removeView() {
      LinearLayout linearLayout = (LinearLayout) findViewById(R.id.linear);
      Button btn_second= (Button) findViewById(R.id.second);
      linearLayout.removeView(btn_second);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-08-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-25
      • 2011-09-01
      • 2020-02-16
      相关资源
      最近更新 更多