在Android列表视图禁止内部滚动 [英] Listview disable internal scrolling on Android

查看:132
本文介绍了在Android列表视图禁止内部滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我需要的全部滚动的布局。布局包含ListView一个底部,这是造成一些不和谐。这里是发生了什么:

所以,你可以看到底部的滚动在自己的小世界,而我需要禁用它们,让它们的增长和扩展整个布局滚动。我试过封装这一切在<滚动型><的LinearLayout>我的资料LT; / LinearLayout中>< /滚动型> ,都无济于事。我试过无限的组合,带match_parentWRAP_CONTENT layout_heights 。我真的需要列表视图向外成长过程中没有把自己在自己的滚动的世界。

 < XML版本=1.0编码=UTF-8&GT?;
< LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
机器人:方向=垂直
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
机器人:重力=中心
>
    < TableLayout
        机器人:layout_width =FILL_PARENT
        机器人:layout_height =WRAP_CONTENT>
        <的TableRow>
            < TableLayout安卓layout_span =2
                机器人:layout_width =FILL_PARENT
                机器人:layout_weight =1>
                <的TableRow安卓重力=中心>
                    <按钮机器人:ID =@ + ID / vin_btn
                        机器人:宽=@扪/ inb_btn_w
                        机器人:身高=@扪/ inb_btn_h
                        机器人:文本=@字符串/ inb_vin_btn
                        机器人:TEXTSIZE =@扪/ inb_txt_sz/>
                    <按钮机器人:ID =@ + ID / clear_btn
                        机器人:宽=@扪/ inb_btn_w
                        机器人:身高=@扪/ inb_btn_h
                        机器人:文本=@字符串/ inb_sc_btn
                        机器人:TEXTSIZE =@扪/ inb_txt_sz/>
                    <按钮机器人:ID =@ + ID / transmit_btn
                        机器人:宽=@扪/ inb_btn_w
                        机器人:身高=@扪/ inb_btn_h
                        机器人:文本=@字符串/ inb_tr_btn
                        机器人:TEXTSIZE =@扪/ inb_txt_sz/>
                < /的TableRow>
            < / TableLayout>
        < /的TableRow>
        <的TableRow安卓重力=center_vertical
            机器人:layout_width =FILL_PARENT>
            <的TextView
                机器人:重力=右
                机器人:ID =@ + ID / text_cust
                机器人:TEXTSIZE =@扪/ inb_txt_sz
                机器人:文本=@字符串/ inb_cust/>
            <微调
                机器人:layout_width =FILL_PARENT
                机器人:layout_weight =1
                机器人:ID =@ + ID / cust_spn/>
        < /的TableRow>
        <的TableRow机器人:layout_width =FILL_PARENT>
            <的TextView
                机器人:重力=右
                机器人:ID =@ + ID / text_drv
                机器人:TEXTSIZE =@扪/ inb_txt_sz
                机器人:文本=@字符串/ inb_drv/>
            <的EditText
                机器人:ID =@ + ID / drv_in
                机器人:inputType =数字
                机器人:layout_width =FILL_PARENT
                机器人:layout_weight =1
                机器人:单线=真/>
        < /的TableRow>
        <的TableRow安卓重力=center_vertical>
            <的TextView
                机器人:重力=右
                机器人:ID =@ + ID / text_prd
                机器人:TEXTSIZE =@扪/ inb_txt_sz
                机器人:文本=@字符串/ inb_prd/>
            <微调
                机器人:ID =@ + ID / prd_spn
                机器人:layout_width =FILL_PARENT
                机器人:layout_weight =1/>
        < /的TableRow>
        <的TableRow安卓重力=center_vertical>
            <的TextView
                机器人:重力=右
                机器人:ID =@ + ID / text_scale
                机器人:TEXTSIZE =@扪/ inb_txt_sz
                机器人:文本=@字符串/ inb_scale/>
            <微调
                机器人:ID =@ + ID / scale_spn
                机器人:layout_width =FILL_PARENT
                机器人:layout_weight =1/>
        < /的TableRow>
        <的TableRow安卓重力=center_vertical>
            <的TextView
                机器人:重力=右
                机器人:ID =@ + ID / text_dir
                机器人:TEXTSIZE =@扪/ inb_txt_sz
                机器人:文本=@字符串/ inb_dir/>
            <微调
                机器人:ID =@ + ID / dir_spn
                机器人:layout_width =FILL_PARENT
                机器人:layout_weight =1/>
        < /的TableRow>
        <的TableRow>
            <的TextView
                机器人:重力=右
                机器人:ID =@ + ID / text_make
                机器人:TEXTSIZE =@扪/ inb_txt_sz
                机器人:文本=@字符串/ inb_make/>
            <的EditText
                机器人:ID =@ + ID / make_in
                机器人:单线=真
                机器人:layout_width =FILL_PARENT
                机器人:layout_weight =1/>
        < /的TableRow>
        <的TableRow>
            <的TextView
                机器人:重力=右
                机器人:ID =@ + ID / text_tag
                机器人:TEXTSIZE =@扪/ inb_txt_sz
                机器人:文本=@字符串/ inb_tag/>
            <的EditText
                机器人:ID =@ + ID / tag_in
                机器人:单线=真
                机器人:layout_width =FILL_PARENT
                机器人:layout_weight =1/>
        < /的TableRow>
    < / TableLayout>
    < ListView的机器人:ID =@ + ID / vin_list
            机器人:isScrollContainer =假
            机器人:layout_weight =1
            机器人:layout_height =match_parent
            机器人:layout_width =match_parent/>
< / LinearLayout中>
 

该行布局定义如下:

 < XML版本=1.0编码=UTF-8&GT?;
< LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
        机器人:layout_width =FILL_PARENT
        机器人:layout_height =WRAP_CONTENT
        机器人:填充=4dip>
    < TableLayout
            机器人:layout_width =WRAP_CONTENT
            机器人:layout_height =WRAP_CONTENT
            机器人:方向=垂直
            机器人:重力=center_vertical |左>
        <的TableRow>
            < TextView的机器人:ID =@ + ID / VIN
                    机器人:layout_width =WRAP_CONTENT
                    机器人:layout_height =WRAP_CONTENT
                    机器人:TEXTSIZE =20SP/>
        < /的TableRow>
        <的TableRow>
            < TextView的机器人:ID =@ + ID /递减
                    机器人:layout_width =WRAP_CONTENT
                    机器人:layout_height =WRAP_CONTENT
                    机器人:TEXTSIZE =12SP/>
        < /的TableRow>
    < / TableLayout>
< / LinearLayout中>
 

解决方案

首先,添加滚动型为根项目的布局,将让你在布局中的所有项目之间滚动(这将是必要的小屏手机现有TableLayout)。

然后更换的ListView通过垂直的LinearLayout和手动充气尽可能多的行,因为你需要用类似的方法:

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

LayoutInflater充气= LayoutInflater.from(getApplicationContext());

为(项目编号:mListItems){
    的LinearLayout llItem =(的LinearLayout)inflater.inflate(R.layout.row,NULL);
    TextView的VIN =(TextView中)llItem.findViewById(R.id.vin);
    vin.setText(item.getFirstText());
    TextView的递减=(TextView中)llItem.findViewById(R.id.desc);
    desc.setText(item.getSecondText());
    //要知道至极项目已被点击
    llItem.setTag(item.getId());
    //在onClickListener刚上车的看法使用getTag()中的id
    llItem.setOnClickListener(本);
    llContainer.addView(llItem);
}
 

根据需要您的滚动型将增加大小尽可能多的,你就可以滚动整个屏幕上。

I have a layout that I need to scroll in its entirety. The layout contains a listview a the bottom, which is causing some discord. Here's what's happening:

So you can see that the bottom scrolls in its own little world, and I need to disable that so it grows and extends the entire layout for scrolling. I've tried encapsulating it all in a <scrollview><linearlayout>mystuff</linearlayout></scrollview>, to no avail. I've tried infinite combinations with "match_parent" and "wrap_content" layout_heights. I really need that listview to grow outward without putting itself in its own scrolling world.

<?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>

the row layout is defined below:

<?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>

解决方案

First of all, add a ScrollView as root item for your layout it will allow you to scroll between all the items in your layout (it will be necessary for the existing TableLayout on small screen phones).

Then replace the ListView by a vertical LinearLayout and inflate manually as much rows as you need with a similar method:

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);
}

Your ScrollView will increase size as much as needed and you will be able to scroll on the entire screen.

这篇关于在Android列表视图禁止内部滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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