【问题标题】:The view visibility does not change视图可见性不变
【发布时间】:2015-07-22 23:49:52
【问题描述】:

我的 java 代码中有一个名为 panel_close 的按钮。在 setOnclickListener 方法中,我更新了一些其他视图的可见性。但是,有时代码似乎无法正确更新面板的可见性。这是代码

panel_close.setOnClickListener(new OnClickListener() {


        @Override
        public void onClick(View v) {
            View temp=findViewById(R.id.show_panel);
            temp.startAnimation(window_close);
            temp.setVisibility(View.GONE);
            compass.setVisibility(View.VISIBLE); // compass is defined as a field. Sometimes the code does not make this view visible
            stats.setVisibility(View.VISIBLE); // stats is defined as a field. Sometimes the code does not make this view visible
            control.setVisibility(View.VISIBLE); // control is defined as a field. Sometimes the code does not make this view visible


            loadAllList(); // this is an AsyncTask
            loadAllpins(); // this is an AsyncTask

        }
    });

任何评论将不胜感激。

【问题讨论】:

  • 什么是panel_close
  • @karakuri panel_close 是一个安卓按钮
  • 那是不可能的。 startAnimation() 不能将 Button 作为参数。

标签: android android-layout android-view


【解决方案1】:

您应该查看在 UI 线程上运行这些更改,以确保修改对 UI 可见:

Android - using runOnUiThread to do UI changes from a thread

【讨论】:

    【解决方案2】:

    您应该首先提供有关变量的详细信息,这可能是因为您正在使布局或类似的东西不可见或消失,孩子们在里面。这将使它们保持隐形。

    【讨论】:

      猜你喜欢
      • 2011-04-10
      • 1970-01-01
      • 2015-02-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-17
      • 2017-10-24
      相关资源
      最近更新 更多