我尝试将滚动复合(垂直滚动)与使用手势(滑动)的分页导航结合使用。
我的应用程序在 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 ) {
}
}
}