Android的ListView控件不滚动? [英] Android ListView that does not scroll?

查看:401
本文介绍了Android的ListView控件不滚动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图做一个布局的是类似的东西到Android市场是如何...在哪里下评论说有什么似乎是一个的ListView 但它不会滚动(整个页面的滚动而不是评论)。我不知道如果连一个ListView,但我想要的东西,看起来像列表视图(即有那些分隔栏并没有什么,但不可滚动)。还有人建议使用的的LinearLayout 代替的ListView ,但我也希望项目可以点击并打开新的活动。请大家帮帮忙?

I'm trying to make a layout that is something similar to how the android market is...where say under comments there is what appears to be a ListView but it does not scroll (the whole page scroll but not the comments). I'm not sure if its even a ListView but I want something that looks like the list view (ie. have those divider bars and what not but NOT SCROLLABLE). There are people suggesting to use a LinearLayout instead of a ListView but I also want the items to be clickable and open a new activity. Please help?

我目前的布局树像这样

<LinearLayout>
  <ScrollView>
     <RelativeLayout>

我希望把里面的内容 RelativeLayout的

推荐答案

作为解释所指出的那样在此从GoogleIo影片从来没有把一个ListView内的滚动视图。如果列表不应该滚动使用的ViewGroup像线性布局,并添加所有项目到这个ViewGroup中在一个循环中的code。如果你想一整排被点击,你必须使用另一个ViewGroup中的每行的根节点,并添加OnClickListener到这一观点。

As explained by the programmers that did the listView in this video from GoogleIo never put a ListView inside a scroll View. If your list should not scroll use a ViewGroup like a linear Layout and add all the items to this ViewGroup in a loop in your code. If you want a whole row to be clickable you have to use another ViewGroup as the root node for each row and add the OnClickListener to this View.

样品code:

LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);

for (int current = 0; current < itemCount; current++) {
   View view = inflater.inflate(R.layout.layout_id, parent, false);

   //initialize the view

   view.setOnClickListener(new OnClickListener() {

      @Override
      public void onClick(View v) {
          Intent intent = new Intent(getApplicationContext(), CLASS_TO_START)
          startActivity(intent);
      }
   });
   viewGroup.addView(view);
   if (current < itemCount - 1) {
      inflater.inflate(R.layout.line, viewGroup);
   }
}

这code会产生一个视图,你有充分的项目,并把它放入的ViewGroup。每一个项目,但最后后,它也将增加一个分隔线的ViewGroup。

This code will generate one View for every item that you have and put it into the viewGroup. After every item but the last it will also add a divider to the viewGroup.

这篇关于Android的ListView控件不滚动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆