为什么有些TableLayout行不会变得不可见?

时间:2016-08-12 08:03:10

标签: android horizontal-scrolling

根据Spinner选择,我替换的表应更改为不可见,但如果它大于新表,则仍会显示一些旧行。当我再次选择相同的选项时,它会正确消失。

示例代码

        Spinner s;
        s.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parentView, View selectedItemView, int position, long id) {
            // your code here
            textSpinner = s.getSelectedItem().toString();
            switch (position){
                case 0:
                    tableLayout2.setVisibility(View.INVISIBLE);
                    tableLayout1.setVisibility(View.VISIBLE);
                    break;
                case 1:
                    tableLayout1.setVisibility(View.INVISIBLE);
                    tableLayout2.setVisibility(View.VISIBLE);
                    break;
            }
        }

1 个答案:

答案 0 :(得分:2)

如果没有看到您的代码和布局,无法查明确切的问题,但使用View.GONE代替View.INVISIBLE可能会起作用:

switch (position){
    case 0:
        tableLayout2.setVisibility(View.GONE);
        tableLayout1.setVisibility(View.VISIBLE);
        break;
    case 1:
        tableLayout1.setVisibility(View.GONE);
        tableLayout2.setVisibility(View.VISIBLE);
        break;
}