0

我正在创建一个带有标题的列表视图。我创建了 header.xml,其中有一个图像。但是当我滚动列表标题时也会滚动。它应该总是在顶部。`public class CustomListActivity extends ListActivity {

    static final String[] Actress = 
               //new String[] { "Katrina Kaif", "Aishwarya", "Genelia", "Vidya", "Khalid", "Khalid", "Khalid", "Khalid", "Khalid", "Khalid", "Khalid", "Khalid", "Khalid", "Khalid"};
    new String[] { "Aishwarya", "Genelia","Katrina Kaif",   "Khalid", "Khalid", "Khalid", "Khalid", "Khalid", "Khalid", "Khalid", "Khalid", "Khalid", "Khalid", "Vidya",};
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ListView lv = getListView();
        View header = getLayoutInflater().inflate(R.layout.header, null);
        lv.addHeaderView(header);
        setListAdapter(new MobileArrayAdapter(getApplicationContext(), Actress));


        lv.setTextFilterEnabled(true);


    }

    @Override
    protected void onListItemClick(ListView l, View v, int position, long id) {

        //get selected items
        String selectedValue = (String) getListAdapter().getItem(position);
        Toast.makeText(this, selectedValue, Toast.LENGTH_SHORT).show();

    }

}`
4

4 回答 4

2

只需在列表视图上方放置一个视图,无需使用标题?

于 2012-04-25T12:48:09.430 回答
1

不要将标题作为另一个单元格,而是创建一个自定义组件。像(总的modo):

<LinearLayout orientation="vertical">
  <Header/>
  <ScrollablePanel>
    <ListView/>
  </ScrollablePanel>
</LinearLayout>
于 2012-04-25T12:48:12.130 回答
0

如果您只是将 header.xml 中的任何视图放在 ListActivity 布局文件中的 ListView 顶部,则它不应该滚动

于 2012-04-25T12:49:25.927 回答
0

尝试这个:

LayoutInflater inflater = getLayoutInflater();
ViewGroup header = (ViewGroup)inflater.inflate(R.layout.header, lv, false);
lv.addHeaderView(header, null, false);
于 2012-04-25T12:54:01.687 回答