ÈçºÎʹÓà floatUI
´´½¨²»Í¬µÄ UI ×é¼þ£¬²¢ÎªËüÃÇÉèÖõã»÷ʼþ¡£Ã¿¸öʾÀý¶¼Õ¹Ê¾Á˲»Í¬µÄ UI ²¼¾ÖºÍʼþ´¦ÀíÂß¼¡£
ʾÀý 1: ´´½¨Ò»¸ö´øÓжà¸ö°´Å¥µÄ´¹Ö±²¼¾Ö£¬²¢ÎªÃ¿¸ö°´Å¥ÉèÖò»Í¬µÄµã»÷ʼþ
var f1 = new floatUI();
f1.loadSXML(`
<vertical>
<button text="°´Å¥1" id="button1"/>
<button text="°´Å¥2" id="button2"/>
<button text="°´Å¥3" id="button3"/>
</vertical>
`);
f1.findViewById('button1').setOnClickListener(function() {
printl("°´Å¥1±»µã»÷ÁË");
});
f1.findViewById('button2').setOnClickListener(function() {
printl("°´Å¥2±»µã»÷ÁË");
});
f1.findViewById('button3').setOnClickListener(function() {
printl("°´Å¥3±»µã»÷ÁË");
});
ʾÀý 2: ´´½¨Ò»¸ö´øÓÐÊäÈë¿òºÍ°´Å¥µÄ²¼¾Ö£¬µã»÷°´Å¥Ê±»ñÈ¡ÊäÈë¿òµÄÄÚÈÝ
var f2 = new floatUI();
f2.loadSXML(`
<vertical>
<input id="input1" hint="ÇëÊäÈëÄÚÈÝ"/>
<button text="Ìá½»" id="submitButton"/>
</vertical>
`);
f2.findViewById('submitButton').setOnClickListener(function() {
var inputText = f2.findViewById('input1').getText();
printl("ÊäÈëµÄÄÚÈÝÊÇ£º" + inputText);
});
ʾÀý 3: ´´½¨Ò»¸ö´øÓи´Ñ¡¿òµÄ²¼¾Ö£¬µã»÷°´Å¥Ê±»ñÈ¡¸´Ñ¡¿òµÄ״̬
var f3 = new floatUI();
f3.loadSXML(`
<vertical>
<checkbox text="Ñ¡Ïî1" id="checkbox1"/>
<checkbox text="Ñ¡Ïî2" id="checkbox2"/>
<button text="È·ÈÏ" id="confirmButton"/>
</vertical>
`);
f3.findViewById('confirmButton').setOnClickListener(function() {
var isChecked1 = f3.findViewById('checkbox1').isChecked();
var isChecked2 = f3.findViewById('checkbox2').isChecked();
printl("Ñ¡Ïî1µÄ״̬£º" + isChecked1);
printl("Ñ¡Ïî2µÄ״̬£º" + isChecked2);
});
ʾÀý 4: ´´½¨Ò»¸ö´øÓнø¶ÈÌõµÄ²¼¾Ö£¬µã»÷°´Å¥Ê±¸üнø¶ÈÌõ
var f4 = new floatUI();
f4.loadSXML(`
<vertical>
<progressbar id="progressBar" max="100"/>
<button text="¸üнø¶È" id="updateButton"/>
</vertical>
`);
f4.findViewById('updateButton').setOnClickListener(function() {
var progressBar = f4.findViewById('progressBar');
var currentProgress = progressBar.getProgress();
progressBar.setProgress(currentProgress + 10);
printl("µ±Ç°½ø¶È£º" + progressBar.getProgress());
});
ʾÀý 5: ´´½¨Ò»¸ö´øÓе¥Ñ¡°´Å¥µÄ²¼¾Ö£¬µã»÷°´Å¥Ê±»ñÈ¡Ñ¡Öеĵ¥Ñ¡°´Å¥
var f5 = new floatUI();
f5.loadSXML(`
<vertical>
<radiogroup id="radioGroup">
<radiobutton text="Ñ¡Ïî1" id="radio1"/>
<radiobutton text="Ñ¡Ïî2" id="radio2"/>
<radiobutton text="Ñ¡Ïî3" id="radio3"/>
</radiogroup>
<button text="È·ÈÏÑ¡Ôñ" id="confirmButton"/>
</vertical>
`);
f5.findViewById('confirmButton').setOnClickListener(function() {
var radioGroup = f5.findViewById('radioGroup');
var selectedId = radioGroup.getCheckedRadioButtonId();
var selectedButton = f5.findViewById(selectedId);
printl("Ñ¡ÖеÄÑ¡ÏîÊÇ£º" + selectedButton.getText());
});
ʾÀý 6: ´´½¨Ò»¸ö´øÓÐͼƬµÄ²¼¾Ö£¬µã»÷°´Å¥Ê±¸ü»»Í¼Æ¬
var f6 = new floatUI();
f6.loadSXML(`
<vertical>
<image id="imageView" src="https://example.com/image1.png"/>
<button text="¸ü»»Í¼Æ¬" id="changeImageButton"/>
</vertical>
`);
f6.findViewById('changeImageButton').setOnClickListener(function() {
var imageView = f6.findViewById('imageView');
imageView.setImage("https://example.com/image2.png");
printl("ͼƬÒѸü»»");
});
ʾÀý 7: ´´½¨Ò»¸ö´øÓÐÁбíµÄ²¼¾Ö£¬µã»÷°´Å¥Ê±»ñÈ¡Ñ¡ÖеÄÁбíÏî
var f7 = new floatUI();
f7.loadSXML(`
<vertical>
<list id="listView">
<item text="Ñ¡Ïî1"/>
<item text="Ñ¡Ïî2"/>
<item text="Ñ¡Ïî3"/>
</list>
<button text="»ñÈ¡Ñ¡ÖÐÏî" id="getSelectedButton"/>
</vertical>
`);
f7.findViewById('getSelectedButton').setOnClickListener(function() {
var listView = f7.findViewById('listView');
var selectedItem = listView.getSelectedItem();
printl("Ñ¡ÖеÄÑ¡ÏîÊÇ£º" + selectedItem.getText());
});
ʾÀý 8: ´´½¨Ò»¸ö´øÓ묶¯ÌõµÄ²¼¾Ö£¬µã»÷°´Å¥Ê±»ñÈ¡»¬¶¯ÌõµÄÖµ
var f8 = new floatUI();
f8.loadSXML(`
<vertical>
<seekbar id="seekBar" max="100"/>
<button text="»ñÈ¡Öµ" id="getValueButton"/>
</vertical>
`);
f8.findViewById('getValueButton').setOnClickListener(function() {
var seekBar = f8.findViewById('seekBar');
var value = seekBar.getProgress();
printl("µ±Ç°»¬¶¯ÌõµÄÖµÊÇ£º" + value);
});
ʾÀý 9: ´´½¨Ò»¸ö´øÓжԻ°¿òµÄ²¼¾Ö£¬µã»÷°´Å¥Ê±ÏÔʾ¶Ô»°¿ò
var f9 = new floatUI();
f9.loadSXML(`
<vertical>
<button text="ÏÔʾ¶Ô»°¿ò" id="showDialogButton"/>
</vertical>
`);
f9.findViewById('showDialogButton').setOnClickListener(function() {
var dialog = new floatUI();
dialog.loadSXML(`
<vertical>
<text text="ÕâÊÇÒ»¸ö¶Ô»°¿ò"/>
<button text="¹Ø±Õ" id="closeButton"/>
</vertical>
`);
dialog.findViewById('closeButton').setOnClickListener(function() {
dialog.dismiss();
});
dialog.show();
});
ʾÀý 10: ´´½¨Ò»¸ö´øÓжà¸ö²¼¾ÖµÄ¸´ÔÓ UI£¬µã»÷°´Å¥Ê±Çл»²¼¾Ö
var f10 = new floatUI();
f10.loadSXML(`
<vertical>
<layout id="layout1">
<text text="ÕâÊDz¼¾Ö1"/>
<button text="Çл»µ½²¼¾Ö2" id="switchToLayout2"/>
</layout>
<layout id="layout2" visibility="gone">
<text text="ÕâÊDz¼¾Ö2"/>
<button text="Çл»µ½²¼¾Ö1" id="switchToLayout1"/>
</layout>
</vertical>
`);
f10.findViewById('switchToLayout2').setOnClickListener(function() {
f10.findViewById('layout1').setVisibility("gone");
f10.findViewById('layout2').setVisibility("visible");
});
f10.findViewById('switchToLayout1').setOnClickListener(function() {
f10.findViewById('layout2').setVisibility("gone");
f10.findViewById('layout1').setVisibility("visible");
});
ÕâЩʾÀýչʾÁËÈçºÎʹÓà floatUI
´´½¨²»Í¬µÄ UI ×é¼þ£¬²¢ÎªËüÃÇÉèÖõã»÷ʼþ¡£Äã¿ÉÒÔ¸ù¾ÝÐèÒªµ÷ÕûÕâЩʾÀý£¬ÒÔÊÊÓ¦ÄãµÄ¾ßÌåÐèÇó¡£
ÒÔÏÂÊÇ10¸ö¸´ÔÓÇÒʵÓÃµÄ floatUI
ʾÀý£¬º¸ÇÁ˲»Í¬µÄ¹¦Äܺͳ¡¾°¡£Ã¿¸öʾÀý¶¼Õ¹Ê¾ÁËÈçºÎ´´½¨ºÍ²Ù×÷¸¡¶¯½çÃ棬²¢Ìí¼Ó²»Í¬µÄ½»»¥Âß¼¡£
1. ¶à°´Å¥Áª¶¯
var f1 = new floatUI();
f1.loadSXML(`
<vertical>
<button text="°´Å¥1" id="button1"/>
<button text="°´Å¥2" id="button2"/>
<button text="°´Å¥3" id="button3"/>
</vertical>
`);
f1.findViewById('button1').setOnClickListener(function() {
printl("°´Å¥1±»µã»÷ÁË");
f1.findViewById('button2').setText("°´Å¥1±»µã»÷ÁË");
});
f1.findViewById('button2').setOnClickListener(function() {
printl("°´Å¥2±»µã»÷ÁË");
f1.findViewById('button3').setText("°´Å¥2±»µã»÷ÁË");
});
f1.findViewById('button3').setOnClickListener(function() {
printl("°´Å¥3±»µã»÷ÁË");
f1.findViewById('button1').setText("°´Å¥3±»µã»÷ÁË");
});
2. ¶¯Ì¬Ìí¼Ó°´Å¥
var f1 = new floatUI();
f1.loadSXML(`
<vertical>
<button text="Ìí¼Ó°´Å¥" id="addButton"/>
<vertical id="buttonContainer"/>
</vertical>
`);
var buttonCount = 0;
f1.findViewById('addButton').setOnClickListener(function() {
buttonCount++;
var newButton = f1.createView('<button text="а´Å¥' + buttonCount + '"/>');
newButton.setOnClickListener(function() {
printl("а´Å¥" + buttonCount + "±»µã»÷ÁË");
});
f1.findViewById('buttonContainer').addView(newButton);
});
3. Çл»½çÃæ
var f1 = new floatUI();
f1.loadSXML(`
<vertical>
<button text="Çл»µ½½çÃæ1" id="switchButton1"/>
<button text="Çл»µ½½çÃæ2" id="switchButton2"/>
<vertical id="container"/>
</vertical>
`);
var view1 = f1.createView('<vertical><text text="ÕâÊǽçÃæ1"/></vertical>');
var view2 = f1.createView('<vertical><text text="ÕâÊǽçÃæ2"/></vertical>');
f1.findViewById('switchButton1').setOnClickListener(function() {
f1.findViewById('container').removeAllViews();
f1.findViewById('container').addView(view1);
});
f1.findViewById('switchButton2').setOnClickListener(function() {
f1.findViewById('container').removeAllViews();
f1.findViewById('container').addView(view2);
});
4. ÊäÈë¿òÓë°´Å¥
var f1 = new floatUI();
f1.loadSXML(`
<vertical>
<input id="inputField" hint="ÇëÊäÈëÄÚÈÝ"/>
<button text="Ìá½»" id="submitButton"/>
<text id="outputText"/>
</vertical>
`);
f1.findViewById('submitButton').setOnClickListener(function() {
var inputText = f1.findViewById('inputField').getText();
f1.findViewById('outputText').setText("ÄãÊäÈëÁË: " + inputText);
});
5. ½ø¶ÈÌõÓë°´Å¥
var f1 = new floatUI();
f1.loadSXML(`
<vertical>
<progressbar id="progressBar" max="100"/>
<button text="¿ªÊ¼¼ÓÔØ" id="startButton"/>
</vertical>
`);
f1.findViewById('startButton').setOnClickListener(function() {
var progress = 0;
var interval = setInterval(function() {
progress += 10;
f1.findViewById('progressBar').setProgress(progress);
if (progress >= 100) {
clearInterval(interval);
printl("¼ÓÔØÍê³É");
}
}, 500);
});
6. ÁбíÓëµã»÷ʼþ
var f1 = new floatUI();
f1.loadSXML(`
<vertical>
<list id="itemList"/>
</vertical>
`);
var items = ["ÏîÄ¿1", "ÏîÄ¿2", "ÏîÄ¿3", "ÏîÄ¿4"];
items.forEach(function(item) {
var listItem = f1.createView('<text text="' + item + '"/>');
listItem.setOnClickListener(function() {
printl("Äãµã»÷ÁË: " + item);
});
f1.findViewById('itemList').addView(listItem);
});
7. ¸´Ñ¡¿òÓë°´Å¥
var f1 = new floatUI();
f1.loadSXML(`
<vertical>
<checkbox text="Ñ¡Ïî1" id="checkbox1"/>
<checkbox text="Ñ¡Ïî2" id="checkbox2"/>
<button text="Ìá½»" id="submitButton"/>
</vertical>
`);
f1.findViewById('submitButton').setOnClickListener(function() {
var isChecked1 = f1.findViewById('checkbox1').isChecked();
var isChecked2 = f1.findViewById('checkbox2').isChecked();
printl("Ñ¡Ïî1: " + isChecked1 + ", Ñ¡Ïî2: " + isChecked2);
});
8. ͼƬÓëµã»÷ʼþ
var f1 = new floatUI();
f1.loadSXML(`
<vertical>
<image id="imageView" src="https://via.placeholder.com/150"/>
<button text="µã»÷ͼƬ" id="imageButton"/>
</vertical>
`);
f1.findViewById('imageButton').setOnClickListener(function() {
printl("ͼƬ±»µã»÷ÁË");
});
9. »¬¶¯ÌõÓëÏÔʾֵ
var f1 = new floatUI();
f1.loadSXML(`
<vertical>
<seekbar id="seekBar" max="100"/>
<text id="seekValue"/>
</vertical>
`);
f1.findViewById('seekBar').setOnSeekBarChangeListener(function(progress) {
f1.findViewById('seekValue').setText("µ±Ç°Öµ: " + progress);
});
10. ¶àÒ³ÃæÇл»
var f1 = new floatUI();
f1.loadSXML(`
<vertical>
<button text="Ò³Ãæ1" id="page1Button"/>
<button text="Ò³Ãæ2" id="page2Button"/>
<vertical id="pageContainer"/>
</vertical>
`);
var page1 = f1.createView('<vertical><text text="ÕâÊÇÒ³Ãæ1"/></vertical>');
var page2 = f1.createView('<vertical><text text="ÕâÊÇÒ³Ãæ2"/></vertical>');
f1.findViewById('page1Button').setOnClickListener(function() {
f1.findViewById('pageContainer').removeAllViews();
f1.findViewById('pageContainer').addView(page1);
});
f1.findViewById('page2Button').setOnClickListener(function() {
f1.findViewById('pageContainer').removeAllViews();
f1.findViewById('pageContainer').addView(page2);
});
×ܽá
ÕâЩʾÀýչʾÁË floatUI
µÄÇ¿´ó¹¦ÄÜ£¬º¸ÇÁË´Ó¼òµ¥µÄ°´Å¥µã»÷µ½¸´ÔӵĽçÃæÇл»ºÍ¶¯Ì¬ÄÚÈݼÓÔØ¡£Äã¿ÉÒÔ¸ù¾Ýʵ¼ÊÐèÇó¶ÔÕâЩ´úÂë½øÐÐÐ޸ĺÍÀ©Õ¹£¬ÒÔʵÏÖ¸ü¸´ÔӵŦÄÜ¡£