我想在代码中实现布局,其实是很简单的布局,但是还是出错,看了半天也没查处错误在哪,请大侠们帮忙看看,附上布局代码
: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); 这重复了
------解决方案--------------------
------解决方案--------------------
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.