Appcelerator更改ScrollView

时间:2016-01-14 16:02:55

标签: titanium appcelerator appcelerator-titanium appcelerator-alloy

我的合金项目中有一个滚动视图,我需要在按下按钮时添加一些视图,但内容高度,可滚动区域不会改变,底部内容会远离视图。 这是我的Alloy View(.xml)文件

<Alloy>
  <Window class="container">
    <ScrollView id="MainView" >
      <View id="innerContent" class="rowLayout">
        <Label>Address 1</Label>
        <TextField id="Address1" class="textArea"></TextField> 
      </View>
    </ScrollView>
    <View id="buttonView">
      <Button id="button" onClick="doClick" title="Add New Address Input" top="10" width="100" height="50" />
    </View>
  </Window>
</Alloy>

我的样式文件(.tss),包含所有样式:

    ".container": {
        backgroundColor:"white",
        height: Titanium.UI.FILL
    }
    "#MainView": { 
        width: Titanium.UI.FILL,
        height: Titanium.UI.FILL,
        scrollType: "vertical",
        layout: "vertical",
        bottom: "100dp",
        top: "20dp",
        borderColor: "#008000",
        borderWidth: "1px",
        left:"2dp",
        right: "2dp"

    }

    "#buttonView" : {
        height: "50dp",
        width: Titanium.UI.FILL,
        right: "10dp",
        left: "10dp",
        bottom: '8dp',
        borderColor: "#000000",
        borderWidth: "1px"
    }
    ".rowLayout": {
        layout: "vertical"
    }
    ".textArea" : {
        height: "70dp",
        width: Titanium.UI.FILL,
        borderColor: "#000000",
        borderWidth: "1dp",
        left: "8dp",
        right: "8dp"
    }

我的控制器(.js)

var counter=0;
function doClick() { 
  counter++;

  var label = Ti.UI.createLabel({
    text: "Address " + counter + " :"
  });
  var textField = Ti.UI.createTextField({
    height: "70dp",
    width: Titanium.UI.FILL,
    borderColor: "#000000",
    borderWidth: "1dp",
    top: "5dp",
    right: "8dp",
    left: "8dp"
  });

  $.innerContent.add(label);
  $.innerContent.add(textField);
}

$.index.open();

The scroll views does not scroll, or if I already set 3 or four inputs it scroll only to the point where the fourth input was

1 个答案:

答案 0 :(得分:4)

要做的第一件事就是将样式从.xml移到.tss以增加概览

尝试将ScrollView高度设置为Ti.UI.SIZE,然后将layout设置为vertical,然后在click功能上添加新视图{ {1}}

但请记住...... top: '5%', bottom: '5%'外面有一个按钮,当ScrollView增加高度

时,它会离开屏幕