Listview禁用Android上的内部滚动

moo*_*ese 1 android listview android-layout android-listview

我有一个布局,我需要完整滚动.布局包含一个列表视图底部,这导致一些不和谐.这是发生了什么: listviewderp

所以你可以看到底部在它自己的小世界中滚动,我需要禁用它,以便它增长并扩展整个布局以进行滚动.我已经尝试将它全部封装在一起<scrollview><linearlayout>mystuff</linearlayout></scrollview>,但无济于事.我尝试过无限组合"match_parent""wrap_content" layout_heights.我真的需要listview在没有将自己置于自己的滚动世界的情况下向外扩展.

<?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>
Run Code Online (Sandbox Code Playgroud)

行布局定义如下:

<?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>
Run Code Online (Sandbox Code Playgroud)

ol_*_*_er 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);
}
Run Code Online (Sandbox Code Playgroud)

您的ScrollView将根据需要增加大小,您将能够在整个屏幕上滚动.