gridview的锁定滚动

发布于 2024-11-24 01:51:49 字数 5691 浏览 1 评论 0原文

我的 UI 中有一个 gridview,但它垂直滚动 我已将所有滚动条属性设置为 false,但它仍在滚动。知道为什么会这样吗?请帮忙。在此处输入图像描述

这是我的布局

   <?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>

I have one gridview in my UI but it scrolls vertically I have set all the scrollbar properties as false but its still scrolling. Any idea why this is so? please help.enter image description here

This is my layout

   <?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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

老娘不死你永远是小三 2024-12-01 01:51:49

尝试为 GridView 添加或重写 setOnTouchListener ,然后在 onTouch 方法中您可以使用如下代码使 gridview 不滚动:

gridview.setOnTouchListener(new OnTouchListener(){

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

});

Try to add or override setOnTouchListener for GridView, then in onTouch method you can use code like this to make gridview not scrolling :

gridview.setOnTouchListener(new OnTouchListener(){

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

});
笛声青案梦长安 2024-12-01 01:51:49

使用这个自定义网格视图。它自动设置高度并且不滚动:

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);
    }
}

Use this custom gridview. It automatically sets the height and does not scroll:

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);
    }
}
铁轨上的流浪者 2024-12-01 01:51:49

GridView 被设计为垂直滚动,我不知道你可以阻止它滚动。如果您不想滚动,请不要使用 GridView。

GridView is designed to scroll vertically, and I am not aware that you can stop it from scrolling. If you do not want scrolling, do not use a GridView.

猫瑾少女 2024-12-01 01:51:49
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;
    }
}
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;
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文