Ada*_*mit 9 layout android landscape margins
我的应用程序只是一个修改过的ImageViewer,可以选择缩放和拖动.包含修改后的Imageviewer有一个RelativeLayout(我想用作AbsoluteLayout).
然后,可以将新元素添加到布局中以将它们置于图像的某些点中.元素的位置(x,y)以像素为单位,因此我想没有其他方式可以通过编程方式添加它们,而不是使用XML.
然后,每次执行拖动或缩放操作时,都会更新这些元素的位置.
问题是,不知何故,图像的像素与RelativeLayout中的像素不匹配!因此项目"或多或少"位于但不在适当的位置(距离(0,0)越远,误差越大).
我已经尝试过的事情:
尝试不同的转换,因为问题可能与位图和布局之间的密度差异有关:
Resources r = getResources();
float x = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 100, r.getDisplayMetrics());
Run Code Online (Sandbox Code Playgroud)尝试在布局中使用不同的方法来设置边距:
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
params.leftMargin = (int) newPosition.x;
params.topMargin = (int) newPosition.y;
element.setLayoutParams(params);
Run Code Online (Sandbox Code Playgroud)我也想在XML中使用RelativeLayout的可用选项,但我真的无法以编程方式找到它,但我可以找到指定维度的方法,我的意思是:
android:layout_marginLeft ="50px" // or "50mm", or dp, or inches...
Run Code Online (Sandbox Code Playgroud)Shr*_*jan 20
您可以通过以下代码设置高度,宽度和边距:
//headView
RelativeLayout.LayoutParams head_params = (RelativeLayout.LayoutParams)headView.getLayoutParams();
head_params.setMargins(80, 0, 0, 0); //substitute parameters for left, top, right, bottom
head_params.height = 60; head_params.width = 200;
headView.setLayoutParams(head_params);
Run Code Online (Sandbox Code Playgroud)
其中headView是您的应用程序的视图.
试试这个:对于相对布局,您可以像这样设置边距:params.setMargins(left, top, right, bottom);
| 归档时间: |
|
| 查看次数: |
33605 次 |
| 最近记录: |