0
我嘗試過使用invalidate()
刷新我的視圖,並且它不起作用。我知道有另一種方式使用draw(Canvas canvas)
刷新。Android查看不刷新
有人可以向我解釋如何以及爲什麼使用繪製方法? 什麼是畫布? (是,視圖我想重繪?)
這是它如何被使用的一些示例代碼:
if(pageNumber == 1)
{
if(pageCount == --lastPageCount)
{
page2Layout.setVisibility(View.GONE);
page1Layout.setVisibility(View.VISIBLE);
}
if(created1 == false)
{
help.setOrientation(LinearLayout.HORIZONTAL);
help.setLayoutParams(params);
helpText.setLayoutParams(params);
helpText.setText("TEST!\n\n" +
"test\n" +
"Test");
help.addView(helpText);
page1Layout.addView(help);
newSheetLayoutV.addView(page1Layout);
created1 = true;
}
}
還有另一部分/份該代碼不工作,因爲它應該(這就是爲什麼我需要使用刷新)。
else if(pageNumber == 4)
{
if(pageCount == ++lastPageCount)
{
page3Layout.setVisibility(View.GONE);
page4Layout.setVisibility(View.VISIBLE);
}
else if (pageCount == --lastPageCount)
{
page5Layout.setVisibility(View.GONE);
page4Layout.setVisibility(View.VISIBLE);
}
if(created4 == false)
{
LinearLayout horizontalPageLayout = new LinearLayout(this);
horizontalPageLayout.setOrientation(LinearLayout.HORIZONTAL);
horizontalPageLayout.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
TextView testText = new TextView(this);
testText.setLayoutParams(params);
testText.setText("Test!");
page4Layout.addView(testText);
newSheetLayoutV.addView(page4Layout);
created4 = true;
}
}
本質上講,當我刪除視圖page1Layout.setVisibility(View.GONE);
,並添加一個新視圖佈局的代碼工作正常,除了刷新!
感謝您的幫助!