图库捕获轨迹球导航

图库水平捕获轨迹球/ dpad导航。 这是一个示例布局,在Gallery的两侧都有按钮:
 <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal"
    xmlns:android="http://schemas.android.com/apk/res/android">
    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" />

    <Gallery
        android:layout_height="match_parent"
        android:id="@+id/gallery"
        android:layout_width="match_parent"
        android:layout_weight="1" />
    <Button
        android:id="@+id/button2"
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" />
 </LinearLayout>
当您使用轨迹球导航到图库时,您无法转到任何一侧的按钮。我尝试将android:nextFocusLeft =“@ id / button”添加到库中。我也尝试将它添加到图库适配器的第一个视图中。 有没有办法解决?     
已邀请:
我想出来了,这是Gallery中的一个错误。解决方法是将Gallery扩展如下:
public class DpadableGallery extends Gallery {

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

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        switch (keyCode) {
        case KeyEvent.KEYCODE_DPAD_LEFT:
             if (getSelectedItemPosition()==0) {
                 return false;
             }
            break;
        case KeyEvent.KEYCODE_DPAD_RIGHT:
            if (getSelectedItemPosition()==(getAdapter().getCount()-1)) {
                return false;
            }
        }

        return super.onKeyDown(keyCode, event);
    }

}
    

要回复问题请先登录注册