我已经为应用程序制作了一个布局,它在我的手机上运行良好但是当我使用较小尺寸的手机来运行它时,用户界面会发生变化并且不符合要求。例如按钮超出屏幕或其顺序的位置变化。我该怎么办?
答案 0 :(得分:1)
您必须为不同的屏幕尺寸和不同的位图绘图开发不同的布局设计,适用于小型,中型,高密度和超高密度屏幕。
布局
$('#file').on('change',function(){
var file_data = $('#file').prop('files')[0];
var form_data = new FormData();
form_data.append('file', file_data);
$.ajax({
url: 'http://localhost/login/index.php/dashboard_main/upload_file',
dataType: 'text', // what to expect back from the server
cache: false,
contentType: false,
processData: false,
data: form_data,
type: 'post',
success: function (response) {
$('.dropable').html(response);
$('.dropable').removeAttr('style');
$(".dropable").css("height:auto");
$(".dropable div.editcontainer").css({"z-index":"99"});
$(".dropable > img").css({"z-index":"-1"});
},
error: function (response) {
alert(response);
}
});
});
对于drawables
public function upload_file() {
$xx['userData'] = $this->session->userdata('userData');
//upload file
$config['upload_path'] = 'images/';
$config['allowed_types'] = 'gif|jpg|png|jpeg';
$config['max_filename'] = '5000000';
$config['encrypt_name'] = FALSE;
$config['max_size'] = '1024000'; //1 MB
$config['file_name'] = $xx['userData']['oauth_uid'].'_'.$_FILES['file']['name'];
if (isset($_FILES['file']['name'])) {
//$new = 'xyz'.$_FILES['file']['name'];
if (file_exists('images/' . $config['file_name'])) {
echo 'File already exists in the desire destination';
} else {
$this->load->library('upload', $config);
$this->upload->initialize($config);
if (!$this->upload->do_upload('file')) {
echo $this->upload->display_errors();
} else {
echo '<img class="uploadtemp" src="'.base_url().'images/' . $config['file_name'].'"><div class="editcontainer" style="height:45px; margin-top:-50px;border:1px solid red;"></div>';
}
}
//echo $_FILES['file']['name'];
} else {
echo 'Image upload unsuccessful';
}
}
将以下代码放入清单
res/layout/mainactivity.xml // layout for normal screen size ("default")
res/layout-small/mainactivity.xml // layout for small screen size
res/layout-large/mainactivity.xml // layout for large screen size
res/layout-xlarge/mainactivity.xml // layout for extra large screen size
res/layout-xlarge-land/mainactivity.xml // layout for extra large in landscape orientation
请查看以下链接以获取更多参考资料
https://developer.android.com/training/multiscreen/screensizes.html -> Diff Screen Size
https://developer.android.com/guide/practices/screens_support.html -> Diff Screen Supports
答案 1 :(得分:1)
单一布局的一些提示:
对于Ex:如果你想在屏幕底部放置一些按钮(例如2),只需使用 RelativeLayout 作为父级,然后使用<{> LinearLayout 。 1}}之后你可以定义按钮,你也可以使用按钮上的重量来水平对齐。
答案 2 :(得分:0)
这是支持不同屏幕尺寸的方法之一。您需要根据屏幕大小创建布局文件夹。 (比如layout-normal,layout-large等)。将xml布局文件放在每个文件夹中。不要使用硬dp / sp值。
通过 Supporting Multiple Screens以获得更多理解。
答案 3 :(得分:0)
使用“布局”中的权重来正确调整视图。 这是最可靠的方法。