我写了一些方法来获取像素,但它不起作用.它给我运行时错误.
实际上我在单独的类中运行此方法并在我的Activity类中初始化
Board board = new Board(this);
board.execute(URL);
Run Code Online (Sandbox Code Playgroud)
此代码以异步方式运行.请帮我.
public float getpixels(int dp){
//Resources r = boardContext.getResources();
//float px = (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dpis, r.getDisplayMetrics());
final float scale = this.boardContext.getResources().getDisplayMetrics().density;
int px = (int) (dp * scale + 0.5f);
return px;
}
Run Code Online (Sandbox Code Playgroud) android ×1