为平板电脑和手机安卓创建布局

时间:2015-08-20 22:59:14

标签: java android android-layout layout hdpi

好的,所以,我已经阅读了很多关于为Android设备创建布局的内容。当我没有时,我以为自己走在了正确的道路上。我的情况是下一个:

我创建了layout-normal,layout-normal-land,layout-small,layout-small-land等...然后,我得到了值-normal-ldpi,values-normal-mdpi和所有其他限定符。我把尺寸放在那些文件夹中,在我的布局中,我只使用它们。这是我的布局代码:

    var draggedData,
    dropLastDragged
    startPosData = {};

function checkIntersect(posData){
    var left = startPosData.left,
        top = startPosData.top,
        right = startPosData.left+startPosData.width,
        bottom = startPosData.top+startPosData.height,
        cornerLeftPos = posData.left,
        cornerTopPos = posData.top;

        cornerLeftPos += startPosData.width/2;
        cornerTopPos += startPosData.height/2;

    if((cornerLeftPos > left && cornerLeftPos < right) && (cornerTopPos > top && cornerTopPos < bottom)){
        return true;    
    }
    return false;
}

$('.drophere').droppable({
  drop: function (event, ui) {
    dropLastDragged = false;
    $(this).html(draggedData);
    $(this).draggable('enable');
  }
}).draggable({
  disabled: true,
  helper: "clone",
  start: function (event, ui) {
    startPosData.left = ui.offset.left;
    startPosData.width = $(this).width();
    startPosData.top = ui.offset.top;
    startPosData.height = $(this).height();
    draggedData = $(this).html();
    $(this).html('Drop here').draggable('disable');
    dropLastDragged = this;
  },
  stop: function(event, ui) {
    if(dropLastDragged){
        if(checkIntersect(ui.offset)){
            $(dropLastDragged).html(ui.helper.html());
            $(dropLastDragged).draggable('enable');
        }
    }
  }
});

$('.dragme').draggable({
  helper: "clone",
  start: function (event, ui) {
    draggedData = $(this).html();
  }
});

但是,当我在我的设备上测试它(三星Galaxy s2 plus)时,它看起来非常好。当我在Nexus 5上进行测试时,它看起来并不紧密。

有关如何为手机和平板电脑的最佳解决方案创建足够数量的布局的任何建议吗?

1 个答案:

答案 0 :(得分:3)

您可以使用这些布局来支持所有屏幕尺寸:

  

layout#适用于手机(可用宽度小于600dp)

     

layout-sw600dp#适用于7英寸平板电脑(600dp宽大)

     

layout-sw720dp#适用于10英寸平板电脑(720dp宽大)

相关问题