两个GridView控件与Android的一个滚动 [英] Two gridView with one scroll in android

查看:211
本文介绍了两个GridView控件与Android的一个滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在一个活动我需要两个GridView的,因为它需要高度为他们每个人拿那么多。没有GridView控件有独立的滚动条,但他们只有一个滚动条。
我想这样的事情。

In a activity i need two GridView each of them take as much as it needs as height. No gridview has separate scrollbar but they have only one scrollbar. I tried something like this.

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<GridView
       android:id="@+id/gridView1"
       android:layout_width="fill_parent"
       android:layout_height="wrap_content"  //as much height as it needs
       android:background="#9C5353"
       android:gravity="center"
       android:horizontalSpacing="20dp"
       android:numColumns="2"
       android:layout_weight="1"
       android:scrollbars="none"
       android:stretchMode="columnWidth"
       android:verticalSpacing="20dp" >      
       </GridView>


    <GridView 
    android:id="@+id/gridView2"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"   //as much height as it needs
    android:scrollbars="none"
    android:numColumns="1"
    android:layout_weight="1"
    android:horizontalSpacing="20dp"
    android:verticalSpacing="20dp"
    android:gravity="center"
    android:stretchMode="columnWidth" > 
    </GridView>

</LinearLayout>

我试过很多次,但无法得到任何的解决方案。
请任何人都可以有这样的??的任何解决方案

I tried many times but cant get any solution. Please can anyone have any solution of this??

推荐答案

您可以设置在 GridView控件固定,并使用滚动型包含它们

you can set the GridView Fixed ,and use ScrollView include them

public class FixedGridView extends GridView {

public FixedGridView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
}

public FixedGridView(Context context, AttributeSet attrs) {
    super(context, attrs);
}

public FixedGridView(Context context) {
    super(context);
}

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    int expandSpec = MeasureSpec.makeMeasureSpec(
            Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);
    super.onMeasure(widthMeasureSpec, expandSpec);

}

}

这篇关于两个GridView控件与Android的一个滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆