1

我尝试将滚动复合(垂直滚动)与使用手势(滑动)的分页导航结合使用。

我的应用程序在 Android 模拟器上运行良好(尝试过 Android 4.0.3、4.1.2、4.3),但我的手机 ZTE Blade III、Androind OS 4.0.4 出现问题。无论方向如何滑动都不起作用 HTC Desire 与 Android 4.4 在横向滑动时存在问题

难道我做错了什么。

我使用 SwipeDemo 入口点(从选项卡)进行了测试。

  private void createSwipeWidget( Composite parent ) {
    final ScrollingComposite scrollableParent = new ScrollingComposite( parent, SWT.V_SCROLL );
    scrollableParent.setLayout( GridLayoutFactory.fillDefaults().create() );
    scrollableParent.setLayoutData( GridDataFactory.fillDefaults()
      .grab( true, true )
      .align( SWT.FILL, SWT.FILL )
      .create() );

    Swipe result = new Swipe( scrollableParent, new DictionarySwipeItemProvider() );
    GridDataFactory.fillDefaults()
      .grab( true, true )
      .align( SWT.FILL, SWT.FILL )
      .applyTo( result.getControl() );
    result.show( 0 );
  }

我也在方法中com.eclipsesource.tabris.demos.swipe.DictionarySwipeItem 给出了提示.hint( SWT.DEFAULT, 500 )createTitleLabel以便启用垂直滚动。

提前致谢

编辑:添加全新的示例/片段

    import org.eclipse.jface.layout.GridDataFactory;
    import org.eclipse.jface.layout.GridLayoutFactory;
    import org.eclipse.rap.rwt.application.EntryPoint;
    import org.eclipse.rap.rwt.application.EntryPointFactory;
    import org.eclipse.swt.SWT;
    import org.eclipse.swt.widgets.Composite;
    import org.eclipse.swt.widgets.Control;
    import org.eclipse.swt.widgets.Label;

    import com.eclipsesource.tabris.ui.AbstractPage;
    import com.eclipsesource.tabris.ui.PageConfiguration;
    import com.eclipsesource.tabris.ui.PageData;
    import com.eclipsesource.tabris.ui.TabrisUIEntryPoint;
    import com.eclipsesource.tabris.ui.UIConfiguration;
    import com.eclipsesource.tabris.widgets.ScrollingComposite;
    import com.eclipsesource.tabris.widgets.swipe.Swipe;
    import com.eclipsesource.tabris.widgets.swipe.SwipeContext;
    import com.eclipsesource.tabris.widgets.swipe.SwipeItem;
    import com.eclipsesource.tabris.widgets.swipe.SwipeItemProvider;

    public class SwipeScrollSnippet implements EntryPointFactory {

      @Override
      public EntryPoint create() {
        return new TabrisUIEntryPoint( createConfiguration() );
      }

      private UIConfiguration createConfiguration() {
        UIConfiguration configuration = new UIConfiguration();
        /*
         * Page with Vertical scroll and swipe component. Swiping does not work at
         * all.
         */
        PageConfiguration page1 = new PageConfiguration( SwipePageWithScroll.class.getName(),
                                                         SwipePageWithScroll.class );
        page1.setTitle( "Swipe page" );
        page1.setTopLevel( true );
        configuration.addPageConfiguration( page1 );
        return configuration;
      }
      /**
       * Page with scroll and swipe components
       */
      public static class SwipePageWithScroll extends AbstractPage {

        /**
         * Creating content of a page with scrolling component and swipe object
         */
        public void createContent( final Composite parent, final PageData data ) {
          final ScrollingComposite scrollableParent = createScrollParent( parent );
          createSwipe( scrollableParent );
        }

        protected ScrollingComposite createScrollParent( final Composite parent ) {
          parent.setLayout( GridLayoutFactory.fillDefaults().numColumns( 1 ).spacing( 0, 0 ).create() );
          final ScrollingComposite scrollableParent = new ScrollingComposite( parent, SWT.V_SCROLL );
          scrollableParent.setLayoutData( GridDataFactory.fillDefaults().grab( true, true ).create() );
          scrollableParent.setLayout( GridLayoutFactory.fillDefaults().create() );
          scrollableParent.setBackground( getUI().getDisplay().getSystemColor( SWT.COLOR_GRAY ) );
          return scrollableParent;
        }

        public Swipe createSwipe( Composite oParent ) {
          Swipe result = new Swipe( oParent, new SimpleSwipeItemProvider() );
          result.getControl().setBackground( getUI().getDisplay().getSystemColor( SWT.COLOR_YELLOW ) );
          GridDataFactory.fillDefaults()
            .grab( true, true )
            .align( SWT.FILL, SWT.FILL )
            .applyTo( result.getControl() );
          return result;
        }
      }
      /**
       * 
       */
      public static class SimpleSwipeItemProvider implements SwipeItemProvider {

        @Override
        public SwipeItem getItem( int oIndex ) {
          return new SimpleSwipeItem( oIndex );
        }

        @Override
        public int getItemCount() {
          return 3;
        }
      }
      /**
       * 
       */
      public static class SimpleSwipeItem implements SwipeItem {

        private int index;

        public SimpleSwipeItem( int oIndex ) {
          super();
          this.index = oIndex;
        }

        @Override
        public Control load( Composite oParent ) {
          Composite composite = new Composite( oParent, SWT.BORDER );
          composite.setLayout( GridLayoutFactory.fillDefaults().create() );
          Label label = new Label( composite, SWT.None );
          label.setText( "Swipe item " + index );
          label.setLayoutData( GridDataFactory.swtDefaults()
            .grab( true, true )
            .hint( SWT.DEFAULT, 500 )
            .align( SWT.CENTER, SWT.CENTER )
            .create() );
          Label bottomLabel = new Label( composite, SWT.None );
          bottomLabel.setText( "Try to swipe" );
          bottomLabel.setLayoutData( GridDataFactory.swtDefaults()
            .grab( true, true )
            .align( SWT.CENTER, SWT.CENTER )
            .create() );
          return composite;
        }

        @Override
        public boolean isPreloadable() {
          return false;
        }

        @Override
        public void deactivate( SwipeContext oContext ) {
        }

        @Override
        public void activate( SwipeContext oContext ) {
        }
      }
    }
4

1 回答 1

0

对我来说,它也适用于模拟器(经过测试的 Android SDK 和 Genymotion),但对于真实设备,我也注意到问题:使用 Motorola Razr i ist 不起作用,使用基于 Android 4.4.2 的 HTC Desire 和 Cynogenmod 它只能纵向工作方向但不是横向。在华硕 fonepad 上,两个方向都可以正常工作。

一个例子:

  1. 克隆存储库https://github.com/eclipsesource/tabris-demos.git
  2. 使用 1.2.1 Tabris 目标平台
  3. 从下面应用更改
  4. 测试刷卡演示(入口点/刷卡)

==================================================== ================================= SwipeDemo.java

import com.eclipsesource.tabris.widgets.ScrollingComposite;

private void createSwipeWidget( Composite parent ) {
    final ScrollingComposite scrollableParent = new ScrollingComposite( parent, SWT.V_SCROLL );
    scrollableParent.setLayout( GridLayoutFactory.fillDefaults().create() );
    scrollableParent.setLayoutData( GridDataFactory.fillDefaults()
      .grab( true, true )
      .align( SWT.FILL, SWT.FILL )
      .create() );
    Swipe result = new Swipe( scrollableParent, new DictionarySwipeItemProvider() );
    GridDataFactory.fillDefaults()
      .grab( true, true )
      .align( SWT.FILL, SWT.FILL )
      .applyTo( result.getControl() );
    result.show( 0 );
  }

==================================================== ================================= DictionarySwipeItem.java

private void createTitleLabel( Composite parent ) {
    Label titleLabel = new Label( parent, SWT.WRAP );
    GridDataFactory.fillDefaults()
      .align( SWT.CENTER, SWT.TOP )
      .grab( true, true )
      .hint( SWT.DEFAULT, 500 )
      .applyTo( titleLabel );
    titleLabel.setForeground( parent.getDisplay().getSystemColor( SWT.COLOR_DARK_GRAY ) );
    titleLabel.setText( "Lesson " + ( index + 1 ) );
    titleLabel.setFont( new Font( parent.getDisplay(), new FontData( "Arial", 30, SWT.BOLD ) ) );
  }
于 2014-02-03T14:26:40.573 回答