AndroidStudio-ConstraintLayout佈局

(function(w,d,s,l,i))(window,document,'script','dataLayer','GTM-KDKMGT');
(function(d, s, id) var js, fjs = d.getElementsByTagName(s)[0]; if (d.getElementById(id)) return; js = d.createElement(s); js.id = id; js.src = "//connect.facebook.net/zh_TW/all.js#xfbml=1&appId=668497826514848"; fjs.parentNode.insertBefore(js, fjs); (document, 'script', 'facebook-jssdk'));






if(BAHAID)
BAHAID = BAHAID.replace(/&/g, "&")
.replace(/, "<")
.replace(/>/g, ">")
.replace(/"/g, """)
.replace(/'/g, "'");

BAHAIDlow = BAHAID.toLowerCase();

document.write('');

document.write('

');
document.write('');
document.write('');
document.write('');
document.write('

');

//document.write('
');
document.write('
');
document.write('
');
document.write('
');
document.write('
');
document.write('
');
document.write('
');
document.write('
');


else
document.write('
');
document.write('');
document.write('
    ');
    document.write('
  • 我要登入
  • ');
    document.write('
  • 註冊
  • ');
    document.write('
  • ');
    document.write('
');
document.write('
');


document.write('
');

document.write(' ');

(function()
var cx = 'partner-pub-9012069346306566:kd3hd85io9c';
var gcse = document.createElement('script');
gcse.type = 'text/javascript';
gcse.async = true;
gcse.src = 'https://cse.google.com/cse.js?cx=' + cx;
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(gcse, s);
)();

service = new rsearch('rsearch');

if( BAHAID )
NOTIFY_getnum();
run30 = setInterval("NOTIFY_getnum()",60000);


function insideSecondaryfunc(frm, evt){
if( 0

















breadCrumbs(122, '', 'homeuid=zeroXoto')








    breadCrumbs_listMenu(122, 0, 'homeuid=zeroXoto')





    創作內容





    0 GP


    AndroidStudio-ConstraintLayout佈局


    作者:音無│2018-10-21 15:41:52│贊助:0│人氣:19
    在AS使用畫面佈局的時候,通常都是在畫面直接拉好位置之後就定位也訂好大小了!


    不過在Android手機種類多到炸裂的時代,螢幕大小真的很讓人頭痛(對我來說啦),

    所以,在佈局的時候,當前已經有ConstraintLayout可以使用。



    先上代碼

    MainActivity.java






    activity_main.xml






    佈局畫面






    包住TextView的是ConstraintLayout

    假使你沒有設定任何的位置訊息,那麼他就會在預設值,左上方(0, 0)

    不過這不是我們要講的重點!



    重點在於MainActivity.java裡面






    這裡在設定項目的Layout佈局時,一定要將LayoutParams設為ConstraintLayout的屬性

    ConstraintLayout.LayoutParams layoutParams_Hello = (ConstraintLayout.LayoutParams) txtHello.getLayoutParams();



    像是這樣,我們才能夠"正確"的使用ConstraintLayout的功能!

    .topMargin = 0;//元件與上方元件的距離


    .topToBottom = R.id.txt_Hello; //元件的Top與txt_Hello的Bottom對齊


    .leftToLeft = R.id.txt_Hello;//元件的Left與txt_Hello的Left對齊

    .width = 80;//元件的寬度Width設定
    執行後就會看見他們一上一下排在左上角了,其他的設定值,多改幾次就會上手了解了!此外說一下我們要因應各種手機螢幕的大小所以必須加上WindowManager windowManager = MainActivity.this.getWindowManager();
    Display display = windowManager.getDefaultDisplay();

    //這樣我們就可以使用display

    display.getWidth();//取得螢幕寬度

    display.getHeight();//取得螢幕高度



    設計版面上,大概就是這樣,其他就是自己思考怎麼樣佈局自己的畫面讓使用者更加方便使用。







    喜歡0
    收藏
    0
    引用
    0
    留言
    推上首頁



    檢舉








    引用網址:https://home.gamer.com.tw/TrackBack.php?sn=4168859

    All rights reserved. 版權所有,保留一切權利





    相關創作

    同標籤作品搜尋:AndroidStudio|ConstraintLayout





    AndroidStudio-EditText的清空Clear




    AndroidStudio-Spinner元件建立Array


    留言共 0 篇留言




    Util.ChangeText('replys', Util.ChangeText.FLAG_LAZYLOAD|Util.ChangeText.FLAG_MAX_SIZE|Util.ChangeText.FLAG_BALA_PLAYER);

    我要留言提醒:您尚未登入,請先登入再留言


    0喜歡★zeroXoto 可決定是否刪除您的留言,請勿發表違反站規文字。



    前一篇:AndroidStudi...








    egg('.MSG-list8C img').each(function(elem)
    elem.className = elem.className + ' lazyload';
    );

    egg('.gallery-image').imageGallery();

    function deleteCreation(vCode)
    var content = egg('.MSG-list8C').html();
    var pattern = /]*?>/i;
    var html = '
    確定要刪除嗎?';
    var width = '200px';
    if(content.match(pattern))
    html += '
    ';

    var boxConfig =
    'closeButton': false,
    'css':
    'width': width

    ;

    egg.mutbox(html, '訊息',
    '確定': function()
    if(egg('#chkDelTruthImage:checked').size())
    egg('[name=delTruthImage]').val('yes');


    egg.cookie.del('ckHOME_CREATION','home.gamer.com.tw','/');
    egg.cookie.set('ckHOME_CREATION',vCode,'home.gamer.com.tw','/');
    document.getElementById('frmDel').submit();
    egg.lightbox.close();
    ,
    '取消': function()
    egg.lightbox.close();

    ,boxConfig);

    var buttonOk = egg('.BH-popbtns :button:eq(0)');
    if(buttonOk.size())
    buttonOk.get(0).focus();



    resizeImage(627);

    egg('.btnGp').click(function()
    $.mutbox('請先登入才能進行此動作', '訊息', '確定':function()location.href='https://user.gamer.com.tw/login.php';);
    );







    訂閱私訊


    作品資料夾


    Q Sharp (1)


    swift_note (1)


    C++ (2)


    楓之谷_成長 (4)


    AndroidStudio (3)


    未分類 (0)


    isara823大家
    歡迎大家來我小屋聽歌~看更多我要大聲說8小時前







    googletag.cmd.push(function() googletag.display('div-gpt-ad-1489070677458-0'); );



    (function(window, $)
    var $window = $(window);
    var $document = $(document);
    var $BH_slave = $("#BH-slave");
    var $BH_master = $("#BH-master");
    var $flySalve = $("#flySalve");
    var posY = $flySalve.position().top;
    var fad_style = document.getElementById("flySalve").style;
    var BH_wrapper_width = $('#BH-wrapper').width();
    var BH_topBar_height = $('.TOP-bh').height();
    $(window).on("scroll", function()
    posY = $BH_slave.height() - (fad_style.position === 'fixed' ? 0 : $flySalve.height());

    if ($document.scrollTop() > (posY + $BH_slave.offset().top - BH_topBar_height) && $BH_slave.height() < $BH_master.height())
    fad_style.position = 'fixed';
    fad_style.top = BH_topBar_height + 'px';
    if ($(window).width() < BH_wrapper_width)
    fad_style.left = (BH_wrapper_width - $BH_slave.width() - $document.scrollLeft())+'px';

    else
    fad_style.position = '';

    ).on("resize", function()
    fad_style.left = null;
    );
    )(window, jQuery);
















    face我們了解您不想看到廣告的心情⋯ 若您願意支持巴哈姆特永續經營,請將 gamer.com.tw 加入廣告阻擋工具的白名單中,謝謝 !【教學】





    The name of the picture黑色沙漠手遊伺服器是巴雷諾斯公會缺人名稱是GO歡迎大家查詢到後加入

    This page is only for reference, If you need detailed information, please check here
    The name of the pictureThe name of the picture

    Popular posts from this blog

    京昆高速公路

    【情報】本週珍珠商品重點:煉金時裝 + 艾港勞工宿舍!!

    【攻略】陳戈-謝勒汗智慧的古書 (完成)