如何禁用按钮寻找" pressed"当库幻灯片是pressed? [英] How to disable button looking "pressed" when Gallery slide is pressed?

查看:188
本文介绍了如何禁用按钮寻找" pressed"当库幻灯片是pressed?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个画廊。每张幻灯片上有一个按钮里面。

I have a gallery. Each slide has a button inside.

我有跟我膨胀的幻灯片的自定义布局。

I have a custom layout which with I'm inflating the slides.

连接点击监听器按钮,它工作得很好,画廊还正常滚动。

Attached a click listener to the button and it works well, gallery also scrolls normally.

但是,当我preSS在画廊按钮之外,按钮也是pressed并变成蓝色。这不会触发按钮的onClickListener。但它使按钮看起来就像是pressed,我不希望出现这种情况。

But when I press on the gallery outside of the button, the button is also pressed and turns blue. This doesn't trigger the onClickListener of the button. But it makes the button look like it was pressed and I don't want that.

尝试设置画廊空的实现,但没有效果的所有监听器...

Tried setting all listeners of the gallery to empty implementations but no effect...

先谢谢了。

编辑:附加一个空的点击监听器自定义布局,现在按钮不会变成蓝色了,但画廊不滚动,因为事件被消耗。会看到什么可以做...

Attached an empty click listener to the custom layout and now the button doesn't become blue anymore but the gallery doesn't scroll because the event is consumed. Will see what can be done...

推荐答案

找到了一种解决方法。这是可怕的,但它的作品。

Found a workaround for this. It's horrible, but it works.

首先,负责我的问题画廊的code部分是这样的:

First of all, the part of Gallery's code responsible for my problem is this:

public boolean onDown(MotionEvent e) {

    // Kill any existing fling/scroll
    mFlingRunnable.stop(false);

    // Get the item's view that was touched
    mDownTouchPosition = pointToPosition((int) e.getX(), (int) e.getY());

    if (mDownTouchPosition >= 0) {
        mDownTouchView = getChildAt(mDownTouchPosition - mFirstPosition);
        mDownTouchView.setPressed(true);
    }

    // Reset the multiple-scroll tracking state
    mIsFirstScroll = true;

    // Must return true to get matching events for this down event.
    return true;
}

更准确地说这行:

More exactly this line:

mDownTouchView.setPressed(true);

下面我幻灯片的布局pssed $ P $和pssed的LinearLayout集$ P $的默认行为是其指派给所有儿童因此所有的孩子都pressed。

Here the layout of my slide is pressed and the default behaviour of setPressed of LinearLayout is dispatching it to all childrens so all children are pressed.

首先,我试图使画廊的一个子类,并覆盖onDown。如果我只是返回false,没有别的,它的工作,但幻灯片了触摸时跳转到下一个幻灯片的奇怪行为。这是因为该行的:

First I tried making a subclass of Gallery and override onDown. If I just returned false and nothing else, it worked but the slides got strange behaviour of jumping to the next slide when touched. That was because of this line:

 mFlingRunnable.stop(false);

这是不执行。由于这个变量是私有及相关的在多媒体类其他一切我没有找到一个方法来从子类中使用它。我也试图复制所有的画廊code,但它也没有工作,因为它使用了很多事情,只有包访问...等。

Which was not executed. Since this variable is private and related to everything else in Gallery class I didn't find a way to use it from the subclass. I tried also copying all the Gallery code, but it also didn't work, because it uses lot of things which only have package access... etc.

因此​​,我创建的LinearLayout的子类,它覆盖发病pressed:

So I created a subclass of LinearLayout, which overrides onSetPressed:

public class LinearLayoutOnSetPressedDoNothing extends LinearLayout {

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

@Override
public void setPressed(boolean pressed) {
}
}

和使用,在我的布局,而不是的LinearLayout:

And use that in my layout instead of the LinearLayout:

<?xml version="1.0" encoding="utf-8"?>
<com.test.LinearLayoutOnPressDoNothing
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
 >

    <!-- content -->
</com.test.LinearLayoutOnPressDoNothing>

和好了,这工作。

这篇关于如何禁用按钮寻找&QUOT; pressed&QUOT;当库幻灯片是pressed?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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