ScrollView 不显示整个 TableLayout

2024-01-03

我想显示一个TableLayout在一个ScrollView。该表有 9 个TableRowScrollView开始显示第四行的部分内容,我无法向上滚动查看上面的行。

XML 布局:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/uyi_choosepi_relativelayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:keepScreenOn="true" >

    <MyGallery
        android:id="@+id/uyi_gallery_originals"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"/>

    <TableLayout
        android:id="@+id/uyi_choosepi_buttontable"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:stretchColumns="0,1" >

        <TableRow >
            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Hilfe"
                android:onClick="showHelp"
                android:drawableLeft="@android:drawable/ic_menu_help" />

            <Button
                android:id="@+id/uyi_choosepi_savepw"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Fertig"
                android:clickable="false"
                android:enabled="false"
                android:onClick="savePassword"
                android:drawableLeft="@android:drawable/ic_menu_save"/>
        </TableRow>
    </TableLayout>

    <ScrollView
            android:id="@+id/uyi_choosepi_scrollview"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_below="@id/uyi_gallery_originals"
        android:layout_above="@id/uyi_choosepi_buttontable">

            <TableLayout
            android:id="@+id/uyi_choosepi_tablelayout"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:gravity="center_vertical|center_horizontal"
            android:layout_gravity="center_vertical"
            android:shrinkColumns="0,1,2" />
    </ScrollView>

</RelativeLayout>

The TableRow是在uyi_choosepi_tablelayout以编程方式添加如下:

table = (TableLayout) findViewById(R.id.uyi_choosepi_tablelayout);

        for (int i = 0; i < UYIMainActivity.PASS_LENGTH; i++) {
            TableRow row = new TableRow(table.getContext());

            originalViews[i] = new ImageView(row.getContext());
            originalViews[i].setAdjustViewBounds(true);
            originalViews[i].setScaleType(ScaleType.FIT_XY);
            originalViews[i].setPadding(3, 3, 3, 3);
            originalViews[i].setImageResource(R.drawable.oempty);

            distortedViews[i] = new ImageView(row.getContext());
            distortedViews[i].setAdjustViewBounds(true);
            distortedViews[i].setScaleType(ScaleType.FIT_XY);
            distortedViews[i].setPadding(3, 3, 3, 3);
            distortedViews[i].setImageResource(R.drawable.wempty);

            ImageView arrow = new ImageView(row.getContext());
            arrow.setAdjustViewBounds(true);
            arrow.setScaleType(ScaleType.FIT_XY);
            arrow.setMaxWidth(80);
            arrow.setPadding(3, 3, 3, 3);
            arrow.setImageResource(R.drawable.arrow_active);


            row.addView(originalViews[i]);
            row.addView(arrow);
            row.addView(distortedViews[i]);
            table.addView(row);
        }

希望你能给我一点提示!


尝试使用 GridView 来代替,这可能会让您更接近您的目标。我最近看到了[这篇博文][1],我会更多地沿着这些思路来处理它。

编辑:我想粘贴这个教程抱歉,http://android-coding.blogspot.com/2011/09/custom-gridview-ii-with-imageview-and.html http://android-coding.blogspot.com/2011/09/custom-gridview-ii-with-imageview-and.html

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

ScrollView 不显示整个 TableLayout 的相关文章

随机推荐