2011-08-10 73 views
1

我有一个布局,我需要整个滚动。布局包含一个列表视图底部,这是造成一些不和谐。这里发生了什么: listviewderpListview禁用Android上的内部滚动

所以你可以看到底部卷轴在它自己的小世界中,我需要禁用它,因此它增长并扩展整个滚动布局。我试过把它封装在<scrollview><linearlayout>mystuff</linearlayout></scrollview>中,但都无济于事。我试过无限组合"match_parent""wrap_content"layout_heights。我真的需要该列表视图向外扩展,而不必将自己置于自己的滚动世界中。

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:gravity="center" 
> 
    <TableLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content"> 
     <TableRow> 
      <TableLayout android:layout_span="2" 
       android:layout_width="fill_parent" 
       android:layout_weight="1"> 
       <TableRow android:gravity="center"> 
        <Button android:id="@+id/vin_btn" 
         android:width="@dimen/inb_btn_w" 
         android:height="@dimen/inb_btn_h" 
         android:text="@string/inb_vin_btn" 
         android:textSize="@dimen/inb_txt_sz" /> 
        <Button android:id="@+id/clear_btn" 
         android:width="@dimen/inb_btn_w" 
         android:height="@dimen/inb_btn_h" 
         android:text="@string/inb_sc_btn" 
         android:textSize="@dimen/inb_txt_sz" /> 
        <Button android:id="@+id/transmit_btn" 
         android:width="@dimen/inb_btn_w" 
         android:height="@dimen/inb_btn_h" 
         android:text="@string/inb_tr_btn" 
         android:textSize="@dimen/inb_txt_sz"/> 
       </TableRow> 
      </TableLayout> 
     </TableRow> 
     <TableRow android:gravity="center_vertical" 
      android:layout_width="fill_parent"> 
      <TextView 
       android:gravity="right" 
       android:id="@+id/text_cust" 
       android:textSize="@dimen/inb_txt_sz" 
       android:text="@string/inb_cust"/> 
      <Spinner 
       android:layout_width="fill_parent" 
       android:layout_weight="1" 
       android:id="@+id/cust_spn"/> 
     </TableRow> 
     <TableRow android:layout_width="fill_parent"> 
      <TextView 
       android:gravity="right" 
       android:id="@+id/text_drv" 
       android:textSize="@dimen/inb_txt_sz" 
       android:text="@string/inb_drv"/> 
      <EditText 
       android:id="@+id/drv_in" 
       android:inputType="number" 
       android:layout_width="fill_parent" 
       android:layout_weight="1" 
       android:singleLine="true"/> 
     </TableRow> 
     <TableRow android:gravity="center_vertical"> 
      <TextView 
       android:gravity="right" 
       android:id="@+id/text_prd" 
       android:textSize="@dimen/inb_txt_sz" 
       android:text="@string/inb_prd"/> 
      <Spinner 
       android:id="@+id/prd_spn" 
       android:layout_width="fill_parent" 
       android:layout_weight="1"/> 
     </TableRow> 
     <TableRow android:gravity="center_vertical"> 
      <TextView 
       android:gravity="right" 
       android:id="@+id/text_scale" 
       android:textSize="@dimen/inb_txt_sz" 
       android:text="@string/inb_scale"/> 
      <Spinner 
       android:id="@+id/scale_spn" 
       android:layout_width="fill_parent" 
       android:layout_weight="1"/> 
     </TableRow> 
     <TableRow android:gravity="center_vertical"> 
      <TextView 
       android:gravity="right" 
       android:id="@+id/text_dir" 
       android:textSize="@dimen/inb_txt_sz" 
       android:text="@string/inb_dir"/> 
      <Spinner 
       android:id="@+id/dir_spn" 
       android:layout_width="fill_parent" 
       android:layout_weight="1"/> 
     </TableRow> 
     <TableRow> 
      <TextView 
       android:gravity="right" 
       android:id="@+id/text_make" 
       android:textSize="@dimen/inb_txt_sz" 
       android:text="@string/inb_make"/> 
      <EditText 
       android:id="@+id/make_in" 
       android:singleLine="true" 
       android:layout_width="fill_parent" 
       android:layout_weight="1"/> 
     </TableRow> 
     <TableRow> 
      <TextView 
       android:gravity="right" 
       android:id="@+id/text_tag" 
       android:textSize="@dimen/inb_txt_sz" 
       android:text="@string/inb_tag"/> 
      <EditText 
       android:id="@+id/tag_in" 
       android:singleLine="true" 
       android:layout_width="fill_parent" 
       android:layout_weight="1"/> 
     </TableRow> 
    </TableLayout> 
    <ListView android:id="@+id/vin_list" 
      android:isScrollContainer="false" 
      android:layout_weight="1" 
      android:layout_height="match_parent" 
      android:layout_width="match_parent" /> 
</LinearLayout> 

行布局定义如下:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:padding="4dip"> 
    <TableLayout 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:orientation="vertical" 
      android:gravity="center_vertical|left"> 
     <TableRow> 
      <TextView android:id="@+id/vin" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:textSize="20sp"/> 
     </TableRow> 
     <TableRow> 
      <TextView android:id="@+id/desc" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:textSize="12sp"/> 
     </TableRow> 
    </TableLayout> 
</LinearLayout> 

回答

0

你可以简单地把所有的行线性布局。我假设你已经定义了一个行布局。你需要做的是循环你的数据,并为每个项目膨胀一行。列表视图支持滚动并使用大量的技巧来消耗比一次显示所有项目更少的资源。

+0

我已经添加了上面的行布局。如你所见,它已经在LinearLayout中。 – moonlightcheese

5

首先,为您的布局添加一个ScrollView作为根项目,它将允许您在布局中的所有项目之间滚动(这对于小屏幕手机上的现有TableLayout是必需的)。

然后通过一个垂直的LinearLayout替代ListView和,你需要用类似的方法充气手动尽可能多行:

LinearLayout llContainer = (LinearLayout) findViewById(R.id.yourBottomLinearLayout); 

LayoutInflater inflater = LayoutInflater.from(getApplicationContext()); 

for (Item item : mListItems){   
    LinearLayout llItem = (LinearLayout) inflater.inflate(R.layout.row, null); 
    TextView vin = (TextView) llItem.findViewById(R.id.vin); 
    vin.setText(item.getFirstText()); 
    TextView desc = (TextView) llItem.findViewById(R.id.desc); 
    desc.setText(item.getSecondText()); 
    // To know wich item has been clicked 
    llItem.setTag(item.getId()); 
    // In the onClickListener just get the id using getTag() on the view 
    llItem.setOnClickListener(this); 
    llContainer.addView(llItem); 
} 

需要你的滚动型将增加大小尽可能多的,你将能够滚动整个屏幕。

+0

那么......这是非常低效的,因为每次进行更新时视图都必须被夸大。这会抛出自定义适配器和convertView窗口,但我看不到没有建立我自己的ListView类,我不打算做的功能。我真的对android平台感到失望,再一次,因为没有先见之明,并不是所有的listviews都应该是他们自己的可滚动容器。 – moonlightcheese

+0

如果你有很多细胞,肯定效率不高。看看我刚刚发布的其他方式。 –

+0

我结束了只是实现了一个TextView,我更新每个vin条目,这不如ListView好,但它的工作原理,这很容易。我失去了很多格式化功能,我完全不满意这一点。这真的是谷歌应该想到的。然而,我标记你的答案是正确的,因为它更加优雅一点,我的解决方案是sl and不驯的。感谢您的意见。 – moonlightcheese

3

其他更好的答案(它昨日尾盘为...)

您可以使用一个简单的ListView和添加页眉TableLayout:

创建的TableView中特定的布局。

在onCreate方法:

LayoutInflater inflater = LayoutInflater.from(getApplicationContext()); 
View headerView = inflater.(R.layout.header, mListView, false); 
mListView.addHeaderView(headerView); 

使用这种方法,你将有包含由ListView的自动管理表格视图中的报头和显示当用户滚动到ListView的开头。

您可以从标准适配器中获得细胞再利用的好处。