これを試してください。 ディメンションの電話機を320 x480と言うと、その上にある単一のボタンの幅と高さを確認できます。以下に示すクラスは、デバイスの幅と高さに基づいて幅と高さを計算します。あなたのボタンの幅と高さを40にする必要があることを知りたければ、calculateWidth()/ calculateHeight()のパラメータとして40を渡します。 ランタイムでは幅と高さが動的に設定されます。
public class DimensionManager {
private int _screenWidth;
private int _screenHeight;
private int _baseScreenWidth = 320;
private int _baseScreenHeight = 480;
public DimensionManager(Activity act) {
WindowManager w = act.getWindowManager();
Display d = w.getDefaultDisplay();
_screenWidth = d.getWidth();
_screenHeight = d.getHeight();
}
/**
*
* @param baseViewWidth Width considering a base Layout.
* @return Returns corresponding width for the device and orientation.
*/
public int calculateWidth(int baseViewWidth) {
return (baseViewWidth * _screenWidth)/_baseScreenWidth;
}
/**
*
* @param baseViewHeight Height considering a base Layout.
* @return Returns corresponding height for the device and orientation.
*/
public int calculateHeight(int baseViewHeight) {
return (baseViewHeight * _screenHeight)/_baseScreenHeight;
}
}
@Caspar KleijneでonLayoutとレイアウト呼び出しでそれをやった、uが解決策を試してみましたか? –
私はOPではない、私はちょうど投稿を編集した。 –