これは、アクティビティレイアウトの階層的な順序が原因で発生します。あなたのActionBar
があなたのビューに描画されています。アクティビティのフレームを見つけてそこにビューを追加することができます。
private void addCircleView() {
final FrameLayout frameLayoutRoot = (FrameLayout) getActivity().getWindow()
.getDecorView().findViewById(android.R.id.content);
View circleView = inflater.inflate(
R.layout.my_circle_view, frameLayoutRoot, false);
ViewGroup.MarginLayoutParams marginLayoutParams =
((ViewGroup.MarginLayoutParams) circleView.getLayoutParams());
marginLayoutParams.topMargin = getStatusBarHeight(getActivity())
+ getActivity().getActionBar().getHeight()
+ getResources().getDimensionPixelSize(R.dimen.your_margin_top_circle);
circleView.setLayoutParams(marginLayoutParams);
frameLayoutRoot.addView(circleView);
}
public int getStatusBarHeight(Context context) {
int result = 0;
final int resourceId = context.getResources().getIdentifier(
"status_bar_height", "dimen", "android");
if (resourceId > 0) {
result = context.getResources().getDimensionPixelSize(resourceId);
}
return result;
}
他のフラグメントに移動するときには、ビューを削除することも忘れないでください。
frameLayoutRoot.removeView(circleView);
編集:
活動している、これはあなたがActionBar
を追加レベルでやるべき何かであることに注意してください。その場合、これらの回避策は必要ありません。このようなものは、ToolBar
で実現するのがより簡単です。
作成し、最初のカスタムビューを膨らま試してみてください、そして、タブ –