4

現在、次のコードを使用して、プログラムで作成したビューの位置を設定しようとしています:

LayoutParams params = bottomBar.getLayoutParams();
params.height = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,(float) 5, getResources().getDisplayMetrics());
params.width = LayoutParams.MATCH_PARENT;
bottomBar.setLayoutParams(params);
bottomBar.setLeft(0);
bottomBar.setTop(this.getHeight()-bottomBar.getHeight());

問題

私が得るエラーは、11 未満の API レベルではプロパティsetLeftとプロパティを使用できないということです。setTop

質問

ビューの位置をプログラムで設定するにはどうすればよいですかAPI level < 11

4

1 に答える 1

2

既にカスタム ビューを作成しているように見えるので、必要なレイアウトをオーバーライドonLayout()して呼び出します。View#layout(int left, int top, int right, int bottom)

final int left = 0;
final int top = getHeight() - bottomBar.getHeight();
final int right = left + bottomBar.getWidth();
final int bottom = top + bottomBar.getHeight();
bottomBar.layout(left, top, right, bottom);
于 2012-08-13T14:31:58.827 に答える