0

私はこのコードを作成しようとしましたが、ヘッダーとフッターが読み込まれると思われる部分でエラーが発生しました..私はこの投稿からこれを取得しました Android ListActivity - ヘッダーとフッターを修正しました間違ったコード...エラーは、エラー: パッケージ 'Android' の属性 '上' のリソース識別子が見つかりません エラー: パッケージ 'アンドロイド' の属性 '下' のリソース識別子が見つかりません

または、私が間違っているときは無視してください

 In main.xml

 <?xml version="1.0" encoding="utf-8"?>
 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

   <include
    android:id="@+id/header_layout"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    layout="@layout/header.xml" />

 <ListView
    android:id="@+id/list_view"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:below="@id/header_layout"
    android:above="@id/footer_layout" />

   <include
    android:id="@+id/footer_layout"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    layout="@layout/footer.xml" />
  </RelativeLayout>
In header.xml

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="fill_parent"
   android:layout_height="fill_parent"
   android:orientation="vertical" >

   <TextView
       android:id="@+id/header_text_view"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content" 
       android:text="Your Application Title"/>
 </LinearLayout>
In footer.xml`enter code here`

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="fill_parent"
 android:layout_height="fill_parent"
 android:orientation="vertical" >

  <Button
       android:id="@+id/done_button"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content" 
       android:text="Done"/>
 </LinearLayout>

活動中はこちら

  public class MainActivity extends ListActivity {

 private ListView mListView;
 @Override
 protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    mListView = (ListView) findViewById(R.id.list_view);
    // Now you can do whatever you want

   }
 }
4

1 に答える 1

2

main.xml のandroid:belowtoandroid:layout_belowandroid:aboveto を変更しますandroid:layout_above

編集:これを達成するには、おそらくよりうまくいく他の方法があります。

オプション A : 代わりに垂直 LinearLayout を使用します。リストビューのレイアウト属性に注意してください。これらにより、ヘッダー ビューとフッター ビューによって占有されていないスペースを埋めるように拡張できます。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <include
        android:id="@+id/header_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        layout="@layout/header.xml" />

    <ListView
        android:id="@android:id/list"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1" />

    <include
        android:id="@+id/footer_layout"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        layout="@layout/footer.xml" />
</LinearLayout>

オプション B : を呼び出さない場合、ListActivity は自動的に ListView を提供しますsetContentView()。この場合、ヘッダー ビューとフッター ビューを自分で作成または拡張し、コードでリストビューに追加します。

public void onCreate(Bundle saved) {
    super(saved);
    ListView list = getListView();
    LayoutInflater inflater = getLayoutInflater();
    View headerView = inflater.inflate(R.layout.header, list, false);
    View footerView = inflater.inflate(R.layout.footer, list, false);

    // these must be called before list.setAdapter()
    list.addHeaderView(headerView);
    list.addFooterView(footerView);
    /* ... */
}
于 2013-04-07T02:49:52.253 に答える