gpt4 book ai didi

android - 页脚和页眉未在 Android ListView 中添加 - 错误修复

转载 作者:搜寻专家 更新时间:2023-11-01 09:09:19 24 4
gpt4 key购买 nike

我正在使用自定义 ListView 。这是我的代码:

protected void onCreate(Bundle savedInstanceState)
{
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
viewInit();

adapter = new myPlanAdapter(this);
LayoutInflater inflater = this.getLayoutInflater();
LinearLayout listFooterView = (LinearLayout) inflater.inflate(
R.layout.violet_footer, null);

listView.addFooterView(listFooterView);

LinearLayout listHeaderView = (LinearLayout) inflater.inflate(
R.layout.blue_header, null);

listView.addHeaderView(listHeaderView);

listView.setAdapter(adapter);

listView.setOnItemClickListener(this);

}

这是我的xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bg"
android:orientation="vertical" >

<LinearLayout
android:layout_width="fill_parent"
android:layout_height="45dp"
android:background="@drawable/head"
android:orientation="horizontal"
android:weightSum="10" >

<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|center_vertical"
android:layout_weight="9"
android:gravity="center"
android:text="My Exam"
android:textAppearance="?android:attr/textAppearanceLarge" />

<Button
android:id="@+id/AddMyPlanButtonId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="@string/add" />
</LinearLayout>

<ListView
android:cacheColorHint="@android:color/transparent"
android:id="@+id/myPlanListViewId"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"/>

</LinearLayout>

这里是 footer.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="25dp"
android:background="@drawable/trans_violet_half_round"
android:orientation="vertical" >
</LinearLayout>

我错过了什么?未添加页眉和页脚。

最佳答案

@Ashish:请在 LinearLayout 中添加一些 View 并尝试,就像我通过添加一个 TextView 更改了 Your footer.xml 文件一样。替换代码并查看结果。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/trans_violet_half_round"
android:orientation="vertical" >

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="test" />

</LinearLayout>

关于android - 页脚和页眉未在 Android ListView 中添加 - 错误修复,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9495126/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com