首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > Android >

android中代码布局的有关问题

2012-08-16 
android中代码布局的问题我想在代码中实现布局,其实是很简单的布局,但是还是出错,看了半天也没查处错误在

android中代码布局的问题
我想在代码中实现布局,其实是很简单的布局,但是还是出错,看了半天也没查处错误在哪,请大侠们帮忙看看,附上布局代码
:linearLayout = new LinearLayout(this);
  setContentView(linearLayout);
  linearLayout.setOrientation(LinearLayout.VERTICAL);

  listViewShowMessage = new ListView(this);
llpListView = new LinearLayout.LayoutParams
(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
linearLayout.addView(listViewShowMessage, llpListView);

loadMore = new Button(this);
loadMore.setText("load");
loadMore.setId(1);
/*llpButton = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT);*/
linearLayout.addView(loadMore, llpButton);
listViewShowMessage.addFooterView(loadMore);

 Logcat中报 ClassCastExceptions 不知道是什么原因造成的?


[解决办法]
报错,贴详细点出来哦
[解决办法]
linearLayout.addView(loadMore, llpButton);
listViewShowMessage.addFooterView(loadMore); 这重复了
[解决办法]

探讨

引用:

linearLayout.addView(loadMore, llpButton);
listViewShowMessage.addFooterView(loadMore); 这重复了
但是我去掉 listViewShowMessage.addFooterView(loadMore)后运行的界面上Button就不会出现了,请问这是什么原因?

[解决办法]
listViewShowMessage = new ListView(this);
llpListView = new LinearLayout.LayoutParams
(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
linearLayout.addView(listViewShowMessage, llpListView);


你把listview的宽、高设都为fill_parent了,可以改成match_parent或者wrap_content,或者给线型布局里的
listview和 button设个权重(weight)试试

[解决办法]
用代码布局太麻烦了,而且容易出错
[解决办法]
你的footerbutton是listview的footer中的,你既然已经添加到listview中了,就不要在添加到linearlayout中去了,如果你还需要一个button的话,就在new一个。从你的布局上来看的话,
你是在linearlayout中实现一个下部带button,上面是listiew的界面。

注意设置权重, 在往linearLayout添加view的时候。把listview, button都设置为1看看。
[解决办法]
那就直接写一个xml文件,用inflater,就可以了,把linearLayout设置为parent layout.

热点排行
Bad Request.