网格视图代码:
<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>
网格项代码:
<?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 上向上滑动大约一分钟后,我也许可以滚动一次。有没有解决这个问题的方法,或者我可以确保整个文本视图允许我滚动它?感谢您的时间。