setSelection不适用于Horizo​​ntalScrollView内的FrameLayout中的gridView

时间:2013-03-13 08:19:28

标签: java android

这是我用于创建水平网格视图的XML文件:

<?xml version="1.0" encoding="utf-8"?>
<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/change_frame_scrollview" 
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
    <FrameLayout
        android:layout_width="wrap_content"
        android:layout_height="match_parent" >
            <GridView
                android:id="@+id/change_frame_gridview"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:stretchMode="columnWidth"
                android:scrollbars="horizontal"
                android:padding="10dp" />
    </FrameLayout>
</HorizontalScrollView>

以下是如何在Activity中实现:

gridView = (GridView) v.findViewById(R.id.change_frame_gridview);
gridView.setAdapter(adapter);
gridView.setNumColumns(adapter.getCount());
gridView.setOnItemClickListener(this);
FrameLayout.LayoutParams params  = new FrameLayout.LayoutParams(
        (adapter.getItemWidth() + FrameThumbnailAdapter.ITEM_MARGIN) * adapter.getCount(),
            LayoutParams.WRAP_CONTENT);
gridView.setLayoutParams(params);
gridView.requestFocus();
gridView.setSelection(10);
adapter.notifyDataSetChanged();

但选择(10)不起作用。

0 个答案:

没有答案