Android 抽屉布局导致选择器变慢
我开始在我的应用程序中实现抽屉布局,我注意到按钮的选择器响应非常慢。当我将抽屉布局更改为线性布局时,延迟消失。我不确定这是否是由于抽屉布局中发生的额外触摸处理造成的,导致了延迟或其他原因。我能做些什么来减少这种滞后Android 抽屉布局导致选择器变慢,android,Android,我开始在我的应用程序中实现抽屉布局,我注意到按钮的选择器响应非常慢。当我将抽屉布局更改为线性布局时,延迟消失。我不确定这是否是由于抽屉布局中发生的额外触摸处理造成的,导致了延迟或其他原因。我能做些什么来减少这种滞后 <android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/drawer_layout
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/my_button"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/button_background"
android:text="" />
</android.support.v4.widget.DrawerLayout>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
<shape>
<solid android:color="#000080"/>
</shape>
</item>
<item>
<shape>
<solid android:color="#0000ff"/>
</shape>
</item>
</selector>
抽屉布局不会像LinearLayout那样覆盖shouldDelayChildPressedState(),因此它会创建一个延迟。必须创建如下布局类:
public class MyDrawerLayout extends DrawerLayout {
public MyDrawerLayout (Context context) {
super(context);
}
public MyDrawerLayout (Context context, AttributeSet attrs) {
super(context, attrs);
}
public MyDrawerLayout (Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
public boolean shouldDelayChildPressedState() {
// prevents touch delay
return false;
}
}
我注意到的唯一的副作用是,在拉出抽屉之前,滑动手势将选择视图