Quantcast
Channel: Appcelerator Developer Center Q&A Tag Feed (android)
Viewing all articles
Browse latest Browse all 7655

ScrollView is not updating when I change properties

$
0
0

I'm working on an app for Android using studio 3.2. Currently testing on a Nexus 10 but it gets used mostly on phones.

Anyhoo. I have a scrollview that I configure at start up based on the device orientation. All is well there. However, when I change orientation my event handler fires, applies the changes for the new orientation but the scrollview stays in the old view. it won't actually make use of the changes. The scrollview is made up of labels.

In portrait the scroll view should scroll up and down, and landscape it should go left and right.

Here's some code. I figure I'm missing something simple.

//result history    
    var resultHistory = Ti.UI.createScrollView({
        contentWidth: Ti.UI.SIZE,
        contentHeight: Ti.UI.SIZE,
        horizontalWrap: false,
    });
    mainContainer.add(resultHistory);
 
    Ti.Gesture.addEventListener('orientationchange',orientationhandler); //orientation changes change the layout
 
    //starting orientation
    if (Ti.Gesture.getOrientation() == Titanium.UI.PORTRAIT) {
        resultHistory.setScrollType('vertical');
        resultHistory.setShowVerticalScrollIndicator(true);
        resultHistory.setShowHorizontalScrollIndicator(false);
        resultHistory.setLayout('vertical');
        resultHistory.setHeight(Ti.UI.SIZE);
        resultHistory.setWidth(Ti.UI.SIZE);
        Ti.API.debug('Orientation '+Ti.Gesture.getOrientation());
    }
    else if (Ti.Gesture.getOrientation() == Titanium.UI.LANDSCAPE_LEFT) {
        resultHistory.setScrollType('horizontal');
        resultHistory.setShowVerticalScrollIndicator(false);
        resultHistory.setShowHorizontalScrollIndicator(true);
        resultHistory.setLayout('horizontal');
        resultHistory.setHeight(Ti.UI.SIZE);
        resultHistory.setWidth(Ti.UI.FILL);
        Ti.API.debug('Orientation '+Ti.Gesture.getOrientation());       
    }
For completeness here is the label that is in the scroll view. Many of them.
//Result Label
            var resultLabel = Ti.UI.createLabel({
                color:AppStyle.altFontColour(),
                text:'',
                height:Ti.UI.SIZE,
                width:Ti.UI.SIZE,
                bottom:5,
                right:5,
                font:{fontSize:AppStyle.fontSize()}
            });

This event handler is firing on oriation changes and the change is getting applied (see the debug outputs)

////////Event Handlers//////////
    var orientationhandler = function(e){
        if (Ti.Gesture.getOrientation() == Titanium.UI.PORTRAIT) {
            resultHistory.setScrollType('vertical');
            resultHistory.setShowVerticalScrollIndicator(true);
            resultHistory.setShowHorizontalScrollIndicator(false);
            resultHistory.setLayout('vertical');
            resultHistory.setHeight(Ti.UI.SIZE);
            resultHistory.setWidth(Ti.UI.SIZE);
            Ti.API.debug('Orientation '+Ti.Gesture.getOrientation());
        }
        else if (Ti.Gesture.getOrientation() == Titanium.UI.LANDSCAPE_LEFT) {
            resultHistory.setScrollType('horizontal');
            resultHistory.setShowVerticalScrollIndicator(false);
            resultHistory.setShowHorizontalScrollIndicator(true);
            resultHistory.setLayout('horizontal');
            resultHistory.setHeight(Ti.UI.SIZE);
            resultHistory.setWidth(Ti.UI.FILL);
            Ti.API.debug('Orientation '+Ti.Gesture.getOrientation());       
        }
        Ti.API.debug("Scroll: "+resultHistory.getScrollType());
    };
[DEBUG] : Orientation 1

[DEBUG] : mali_winsys: new_window_surface returns 0x3000

[DEBUG] : Orientation 2

[DEBUG] : mali_winsys: new_window_surface returns 0x3000

So that's everything. But despite the handler firing and updating the scrollview, it will not update the view and put the new layout and scrolltype into effect.


Viewing all articles
Browse latest Browse all 7655

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>