Блокировка прокрутки gridview - PullRequest
3 голосов
/ 13 июля 2011

У меня есть один вид сетки в моем пользовательском интерфейсе, но он прокручивается по вертикали. Я установил все свойства полосы прокрутки как ложные, но он все еще прокручивается.Есть идеи, почему это так?пожалуйста, помогите. enter image description here

Это мой макет

   <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent" android:layout_height="match_parent"
    android:background="@drawable/bg_im" android:id="@+id/rLayout" android:isScrollContainer="false">

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/lLayoutCalendar" android:orientation="vertical"
        android:layout_width="wrap_content" android:layout_height="wrap_content"
        android:layout_toRightOf="@+id/linearLayoutLeftTask" android:gravity="center_horizontal"
        android:layout_marginLeft="10dp" android:layout_marginRight="10dp"
        android:layout_marginTop="20dp" android:background="@drawable/calendar_bgnew" android:isScrollContainer="false">

        <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:orientation="horizontal" android:layout_width="fill_parent"
            android:layout_height="wrap_content" android:layout_gravity="center_vertical"
            android:scrollbars="none" android:isScrollContainer="false"
            android:layout_marginTop="8dp">

            <ImageView android:id="@+id/prevMonth"
                android:layout_width="wrap_content" android:layout_marginLeft="10dp"
                android:layout_marginTop="5dp" android:layout_height="wrap_content"
                android:src="@drawable/calendar_arrow_previous">
            </ImageView>
            <Button android:id="@+id/currentMonth" android:layout_weight="0.8"
                android:textColor="@android:color/black" android:textAppearance="?android:attr/textAppearanceMedium"
                android:background="@android:color/transparent" android:textStyle="bold"
                android:textSize="16sp" android:layout_width="wrap_content"
                android:layout_height="wrap_content">
            </Button>
            <ImageView android:id="@+id/nextMonth"
                android:layout_marginRight="10dp" android:layout_marginTop="5dp"
                android:layout_width="wrap_content" android:layout_height="wrap_content"
                android:src="@drawable/calendar_arrow_next">
            </ImageView>
        </LinearLayout>
        <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:orientation="horizontal" android:layout_width="fill_parent"
            android:layout_height="wrap_content" android:paddingLeft="5dp"
            android:layout_marginTop="10dp" android:paddingRight="5dp">

            <TextView android:typeface="sans" android:layout_marginTop="12dp"
                android:paddingLeft="5dp" android:text="Su" android:layout_height="wrap_content"
                android:textStyle="normal" android:textColor="#7e7f7e"
                android:layout_width="65px">
            </TextView>
            <TextView android:typeface="sans" android:layout_marginTop="12dp"
                android:text="Mo" android:layout_height="wrap_content"
                android:textStyle="normal" android:textColor="#7e7f7e"
                android:layout_width="65px">
            </TextView>
            <TextView android:typeface="sans" android:layout_marginTop="12dp"
                android:text="Tu" android:layout_height="wrap_content"
                android:textStyle="normal" android:textColor="#7e7f7e"
                android:layout_width="63px">
            </TextView>
            <TextView android:typeface="sans" android:layout_marginTop="12dp"
                android:text="We" android:layout_height="wrap_content"
                android:textStyle="normal" android:textColor="#7e7f7e"
                android:layout_width="63px">
            </TextView>
            <TextView android:typeface="sans" android:layout_marginTop="12dp"
                android:text="Th" android:layout_height="wrap_content"
                android:textStyle="normal" android:textColor="#7e7f7e"
                android:layout_width="63px">
            </TextView>
            <TextView android:typeface="sans" android:layout_marginTop="12dp"
                android:text="Fr" android:layout_height="wrap_content"
                android:textStyle="normal" android:textColor="#7e7f7e"
                android:layout_width="63px">
            </TextView>
            <TextView android:typeface="sans" android:layout_marginTop="12dp"
                android:paddingLeft="5dp" android:text="Sa" android:layout_height="wrap_content"
                android:textStyle="normal" android:textColor="#7e7f7e"
                android:layout_width="63px">
            </TextView>
        </LinearLayout>
        <GridView android:numColumns="7" android:layout_marginTop="5dp"  style="overflow:lock"
            android:layout_marginBottom="10dp" android:layout_width="fill_parent"
            android:layout_height="wrap_content" android:id="@+id/calendar"
            android:horizontalSpacing="-1px" android:verticalSpacing="-1px"
            android:layout_marginLeft="2dp" android:isScrollContainer="false"
            android:smoothScrollbar="false" android:stackFromBottom="false"
             android:fastScrollEnabled="false" android:stretchMode="columnWidth" android:fadeScrollbars="false">
        </GridView>
    </LinearLayout>
</RelativeLayout>

Ответы [ 4 ]

6 голосов
/ 13 марта 2012

Попробуйте добавить или переопределить setOnTouchListener для GridView, затем в методе onTouch вы можете использовать такой код, чтобы сделать просмотр сетки без прокрутки:

gridview.setOnTouchListener(new OnTouchListener(){

    @Override
    public boolean onTouch(View v, MotionEvent event) {
        if(event.getAction() == MotionEvent.ACTION_MOVE){
            return true;
        }
        return false;
    }

});
3 голосов
/ 07 августа 2014

Используйте этот пользовательский вид сетки.Он автоматически устанавливает высоту и не прокручивает:

public class MyGridView extends GridView {
    public MyGridView(Context context) {
        super(context);
    }

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

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

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        int heightSpec;

        if (getLayoutParams().height == LayoutParams.WRAP_CONTENT) {
            // The great Android "hackatlon", the love, the magic.
            // The two leftmost bits in the height measure spec have
            // a special meaning, hence we can't use them to describe height.
            heightSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);
        } else {
            heightSpec = heightMeasureSpec;
        }

        super.onMeasure(widthMeasureSpec, heightSpec);
    }
}
1 голос
/ 13 июля 2011

GridView предназначен для вертикальной прокрутки, и я не знаю, что вы можете остановить его от прокрутки.Если вам не нужна прокрутка, не используйте GridView.

0 голосов
/ 22 августа 2012
public class myGridView extends GridView {

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

    @Override
    public boolean onTouchEvent(MotionEvent event) {

    switch(event.getAction()){

    case MotionEvent.ACTION_DOWN:
    return super.onTouchEvent(event);

    case MotionEvent.ACTION_MOVE:
    //Do nothing here!!!
    break;

    case MotionEvent.ACTION_UP:
    return super.onTouchEvent(event);
    }

    //false return 
    return false;
    }
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...