热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

ListView中不显示HeaderView

ListView中加了头和尾后不显示HeaderView。当ListView高度为精确值时(dp)没问题。但当为match_parent和wrap_content时就只能看到尾了,看不到头(头成
ListView中加了头和尾后不显示HeaderView。当ListView高度为精确值时(dp)没问题。但当为match_parent和wrap_content时就只能看到尾了,看不到头(头成是空白了),请各位帮忙看一下。
activity_main.xml:

    xmlns:tools="http://schemas.android.com/tools"
    android:layout_
    android:layout_
    android:orientation="vertical" >
    android:id="@+id/lv"
    android:layout_
     android:layout_ >
    


listfooter.xml:

    android:id="@+id/ll_listfooter"
    android:layout_
    android:layout_
    android:orientation="vertical" >

             android:id="@+id/btn_load_more"
        android:layout_
        android:layout_
        android:text="Loading" />


MainActivity.java
public class MainActivity extends Activity {
ListView lv = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
View listfooter = LayoutInflater.from(this).inflate(R.layout.listfooter, null);
lv = (ListView) this.findViewById(R.id.lv);
lv.addFooterView(listfooter, null, true);
lv.addHeaderView(listfooter, null, true);
lv.setAdapter(new ArrayAdapter(this, android.R.layout.simple_expandable_list_item_1,getData()));
Toast.makeText(this, " "+lv.getCount(), Toast.LENGTH_SHORT).show();
}
private List getData(){
        
        List data = new ArrayList();
        data.add("测试数据1");
        data.add("测试数据2");
        data.add("测试数据3");
        data.add("测试数据4");
         
        return data;
    }
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}



推荐阅读
author-avatar
你的美丽来自我的设计
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有