GridView中的Textview很难滚动

时间:2013-07-06 18:41:59

标签: android gridview scroll textview

GridView代码:

<GridView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/activity_graph"
        android:verticalSpacing="0dip"
        android:horizontalSpacing="5dip"
        android:stretchMode="columnWidth"
        android:gravity="center"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="#0000FF">
        </GridView>

GridItem代码:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:id="@+id/GridItem"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical"
                android:gravity="center_horizontal"
                android:paddingTop="20px"
                android:paddingBottom="20px"
                android:background="#00FF00">


    <TextView android:id="@+id/grid_item_vote_count"

              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:gravity="center_horizontal"
              android:layout_centerHorizontal="true">
    </TextView>

    <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="#ABABAB">

    <TextView android:id="@+id/grid_item_answer"
              android:layout_alignParentBottom="true"
              android:layout_width="match_parent"
              android:layout_height="150dp"
              android:gravity="center_horizontal"
              android:layout_centerHorizontal="true"
              android:focusable="true"
              android:focusableInTouchMode="true"
              android:fadeScrollbars="false"
              android:scrollbars="vertical"
              >
    </TextView>

    <ImageView android:id="@+id/grid_item_bar"
               android:layout_width="20px"
               android:layout_above="@id/grid_item_answer"
               android:layout_height="wrap_content"
               android:layout_centerHorizontal="true"
               >
    </ImageView>

    </RelativeLayout>

</LinearLayout>

适配器:

 @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View myView  = null;
        float height = parent.getHeight();
        if(convertView==null) {
            LayoutInflater li = (LayoutInflater) parent.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            myView = li.inflate(R.layout.grid_item, null);

        }else{
            myView = convertView;
        }
        myView.setMinimumHeight((int)height);

        int numVotes = -1;
        String answer = answerText[position];

        switch(position) {
            case 0:
                numVotes = answerCount1;
                break;
            case 1:
                numVotes = answerCount2;
                break;
            case 2:
                numVotes = answerCount3;
                break;
            case 3:
                numVotes = answerCount4;
                break;
            default:
                Log.d("JK", "Getting view for too high position");
        }

        TextView tv = (TextView) myView.findViewById(R.id.grid_item_vote_count);
        tv.setText(Integer.toString(numVotes));
        tv.setTextColor(Color.BLACK);
        int barHeight = (int) (0.7f * height * ((float) numVotes / maxVotes));

        ImageView imageView =(ImageView) myView.findViewById(R.id.grid_item_bar);
        imageView.setImageDrawable(new ColorDrawable(getColor(position)));
        RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) imageView.getLayoutParams();
        params.height = barHeight;
        imageView.setLayoutParams(params);
        //imageView.setLayoutParams(new RelativeLayout.LayoutParams(16, barHeight));

        tv = (TextView) myView.findViewById(R.id.grid_item_answer);
        tv.setText(answer);
        tv.setTextColor(Color.BLACK);
        tv.setMovementMethod(ScrollingMovementMethod.getInstance());

        return myView;
    }

通过上面的内容,我可以在我的答案textview中看到垂直滚动条,但似乎我必须将手指移动到textview的一个非常特定的部分才能滚动它。在textview上向上滑动大约一分钟后,我可以滚动一次。有没有解决这个或一种方式我可以确保整个textview允许我滚动它?谢谢你的时间。

1 个答案:

答案 0 :(得分:0)

不确定,但可能是因为您将其中一个内部文本视图设置为可滚动,这会混淆父AdapterView的滚动属性:

<TextView android:id="@+id/grid_item_answer"
          android:layout_alignParentBottom="true"
          android:layout_width="match_parent"
          android:layout_height="150dp"
          android:gravity="center_horizontal"
          android:layout_centerHorizontal="true"
          android:focusable="true"  //<-- this
          android:focusableInTouchMode="true" //<--- this
          android:fadeScrollbars="false" //<-- this
          android:scrollbars="vertical"  //<--- this
          >