【发布时间】:2019-11-28 11:27:23
【问题描述】:
我可以使用任何可以直接缩放的单位吗?真的是用 px 编写所有内容并乘以正确比例的唯一方法吗?
(scale = <real screen height>/<template base height> . and every dimension is <dimen in px> * scale)
桶方法的“dp”不适用于我 - 我正在为小屏幕编写,其中元素在触发下一个 dp 缩放阈值之前远离屏幕。
目前我在画布上绘图的解决方法是(如下),但我不知道如何使用 xml 布局来协调它
@Override
public void onSurfaceChanged(SurfaceHolder holder, int format, int width, int height) {
super.onSurfaceChanged(holder, format, width, height);
screenScale = ((float) width) / (float) mBackgroundBitmap.getWidth();
mTopBarYOffset = mTopBarYOffset * screenScale;
mTopBarXOffset = mTopBarXOffset * screenScale;
//and so on for every dimension
【问题讨论】:
-
我正在尝试将布局元素与预先绘制在背景上的边框对齐,因此我需要它在每个屏幕上看起来完全相同,但大致相同 - 3px 的差异会使整个布局关闭。像 %(of screen) 这样的单位是理想的,但它不存在。
标签: android android-layout android-imageview