是否可以在Android中设置视图的绝对位置?(我知道有一个AbsoluteLayout,但它被弃用了......)
例如,如果我有一个240x320px的屏幕,我怎么能添加一个ImageView20x20px,使其中心位于(100,100)?
我是Android新手.我喜欢在任何我想要的地方拥有自由范围的绘图对象.所以我一直在使用Absolute Layout.我收到一条消息,说要使用不同的布局.而且我已经读到这是因为不同手机的不同分辨率.我的问题是,这是不使用绝对布局的唯一原因吗?我制作了一个使用指标来调整像素的方法.
public int widthRatio(double ratioIn){
DisplayMetrics dm = new DisplayMetrics(); //gets screen properties
getWindowManager().getDefaultDisplay().getMetrics(dm);
double screenWidth = dm.widthPixels; //gets screen height
double ratio = screenWidth/100; //gets the ratio in terms of %
int displayWidth = (int)(ratio*ratioIn); //multiplies ratio desired % of screen
return displayWidth;
}
//method to get height or Ypos that is a one size fits all
public int heightRatio(double ratioIn){
DisplayMetrics dm = new DisplayMetrics(); //gets screen properties
getWindowManager().getDefaultDisplay().getMetrics(dm);
double screenHeight = dm.heightPixels; //gets screen height
double …Run Code Online (Sandbox Code Playgroud) 我有一个TextView.如何使用x和y坐标定位?
TextView leftArrow = new TextView(this);
leftArrow.setTypeface(tf);
leftArrow.setText("<");
leftArrow.setTextSize(30);
ll.addView(leftArrow);
Run Code Online (Sandbox Code Playgroud)