编辑:tl; dr:WebView显示为白色框,即使我似乎正确设置了它,并且确实它在前两次都能正常工作,但随后失败)WebView在第二次初始化后显示为纯白色框
编辑:Video showing the problem in action...
我有膨胀从该定义它的XML视图(其中包含一个web视图)下面的代码位:
private void createCard(ViewGroup cvFrame, Card card) {
//... setup vairables...
cvFrame.clearDisappearingChildren();
cvFrame.clearAnimation();
try {
View cv = LayoutInflater.from(getBaseContext()).inflate(R.layout.card_back_view,
cvFrame, true);
cv.setBackgroundDrawable(Drawable.createFromStream(mngr.open(deckName + "_Card_back.png"), deckName));
TextView suit = (TextView)cv.findViewWithTag("card_back_suit");
//...setup text view for suit, this code works fine every time...
WebView title = (WebView)cv.findViewWithTag("card_back_title");
//This WebView doesn't appear to be the one which actually appears on screen (I can change settings till I'm blue in the face, with no effect)
if (title != null) {
title.setBackgroundColor(0x00000000);
title.loadData(titleText, "text/html", "UTF-8");
} else {
Log.e("CardView", "Error can't find title WebView");
}
} catch (IOException e) {
Log.e("CardView", "Error making cards: ", e);
}
}
当这个方法被称为作为onCreate会议的一部分在我的Activity中,WebView包含正确的代码,并且适当透明。
我有一个手势监听器,它用不同的内容替换ViewGroup的内容(它将顶部卡片向左移动,用卡片2替换顶部卡片的内容,放回顶部卡片,然后替换卡片2卡3)
//Gesture listener event
ViewGroup cvFrame = (ViewGroup)findViewById(R.id.firstCard);
cardLoc++
cvFrame.startAnimation(slideLeft);
(onAnimationEnd代码)
public void onAnimationEnd(Animation animation) {
if (animation == slideLeft) {
ViewGroup cvFrameOldFront = (ViewGroup)findViewById(R.id.firstCard);
ViewGroup cvFrameNewFront = (ViewGroup)findViewById(R.id.secondCard);
createCard(cvFrameOldFront, cards.get((cardLoc)%cards.size()));
createCard(cvFrameNewFront, cards.get((cardLoc+1)%cards.size()));
TranslateAnimation slideBack = new TranslateAnimation(0,0,0,0);
slideBack.setDuration(1);
slideBack.setFillAfter(true);
cvFrameOldFront.startAnimation(slideBack);
}
}
当动画已经发生和我替换的牌的内容,TextView的suit
被替换精细和代码绝对通过穿过代码t o替换WebView的内容,但由于某种原因,我最终得到了一个白色的矩形,表示WebView的大小和形状,没有内容,没有透明度。
如果我改变的WebView到一个TextView,它的内容被替换细,所以它的出现只与WebView控件的一个问题:S
谁能告诉我为什么/提示修复?
titleText中有什么?我假设它的HTML代码。 – JoxTraex 2013-02-25 08:31:52
它只是简单的HTML片段 - 它只需要富文本能力,如此粗体,斜体等。 – 2013-02-25 08:38:38
如果您只需要使用简单的标签,为什么不使用像这样的HTML的'TextView':'textView.setText (Html.fromHtml(“标题”)'?检查[这篇文章](http://commonsware.com/blog/Android/2010/05/26/html-tags-supported-by-textview.html)for (TextView)支持的HTML标签列表 – 2013-02-25 09:17:57