を削除します。 fitsSystemWindows
を削除すると、パディングが戻ってきます。どうして? fitsSystemWindows
とパディングをどうすれば保持できますか?fitsSystemWindowsは、私は私のレイアウトでこれを持ってパディング
答えて
fitsSyatemWindows
属性オーバーライドパディングがレイアウトを適用しました。だから、パディングを適用する
、あなたのRelativeLayout
に1つのラッパーのレイアウトを作成し、それにfitsSystemWindows
属性を追加し、子供RelativeLayout
にpadding
必要があります。
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/primary"
android:fitsSystemWindows="true"> //this is container layout
<RelativeLayout
android:paddingLeft="32dp"
android:paddingRight="32dp"
..... > //now you can add padding to this
.....
</RelativeLayout>
</RelativeLayout>
それは、それ自体がパディングを無視しているわけではなく、fitsSystemWindows **は、ビューをシステムウィンドウに合わせるのに十分なパディングを持つパディングをオーバーライドします。 – ianhanniballake
@ianhanniballake aw!私の間違いを修正してくれてありがとう:)答えを改善する – Apurva
誰もがfitSystemWindowsを使用した場合トップパディングを削除する必要がある場合に、私はここにこれを追加します。これは、カスタムアクションバー、DrawerLayout/NavigationView、および/またはフラグメントを使用する場合に当てはまります。
public class CustomFrameLayout extends FrameLayout {
public CustomFrameLayout(Context context) {
super(context);
}
public CustomFrameLayout(Context context, AttributeSet attrs) {
super(context, attrs);
}
public CustomFrameLayout(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public CustomFrameLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}
@Override
protected boolean fitSystemWindows(Rect insets) {
// this is added so we can "consume" the padding which is added because
// `android:fitsSystemWindows="true"` was added to the XML tag of View.
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN
&& Build.VERSION.SDK_INT < 20) {
insets.top = 0;
// remove height of NavBar so that it does add padding at bottom.
insets.bottom -= heightOfNavigationBar;
}
return super.fitSystemWindows(insets);
}
@Override
public WindowInsets onApplyWindowInsets(WindowInsets insets) {
// executed by API >= 20.
// removes the empty padding at the bottom which equals that of the height of NavBar.
setPadding(0, 0, 0, insets.getSystemWindowInsetBottom() - heightOfNavigationBar);
return insets.consumeSystemWindowInsets();
}
}
は、我々は(私の場合でframeLayoutを)レイアウトクラスを拡張し、(API> = 20の場合)またはonApplyWindowInsets()
(API < 20用)fitSystemWindows()
でトップのパディングを削除する必要があります。
- 1. のPHPのは、私がこれを持って私のHTMLレイアウト
- 2. は、私は私のレイアウトの一部としてこれを持って
- 3. 私は2レイアウトでアダプターを持って
- 4. のAndroidのEditTextが、私は私のアプリでは、次のレイアウト持って余分なパディング
- 5. は、私はこのレイアウトを持っている別の要素
- 6. EventToCommand項目はこれは私がXAMLで持っているレイアウトでのItemsControl
- 7. は、私は私のメインインデックスビューでこれらのActionLinksを持って
- 8. Framework7ナビゲーションは、私は私の-app.jsでこれを持って
- 9. は、私はこれを持って
- 10. jQueryのは - 私はこれ持って、
- 11. 私はこれまでのところ、私はこれを持って
- 12. パディング私は、パディングとアンカーリンク持たボタン
- 13. 私は次の表を持って上下のパディング
- 14. レールは3分content_forは、私はこれを持っていレイアウト(application.html)を持っている
- 15. 私のツールバーには、私は次のレイアウトを持っている私のマップ
- 16. 私は私のコードでこれを持って<%= for %>ビューヘルパー
- 17. タブバーdidSelectItemは、私がこれを持って私のヘッダファイルで
- 18. 私はこれを持って、私のconfigure.acファイルでファイル
- 19. 私は私のモデルでこれを持って
- 20. は私が私のGradleでこれを持ってsourceSets.main.runtimeClasspath
- 21. 私は私の中でこれを持って$ _POST配列
- 22. タグ私はこれを持って
- 23. 私はこれ持ってArrayListの
- 24. は、私はこれを持って私のindex.jsファイルにReactDOM.render
- 25. SpringMVC私のSessionFactoryのは、私は私のサーブレットでこれを持って
- 26. は、私は私のSPでこのコードを持ってsp_executesqlを
- 27. ハウツー要素はこれまでのところ、私はこのレイアウトのコードを持って
- 28. onTouchは()私はこのようなレイアウトを持つ親のレイアウト
- 29. は、私はこのコードを持って
- 30. は、私はこのコードを持って
この記事は、[なぜ私はfitsSystemWindowsになりたいのですか?](https://medium.com/google-developers/why-would-i-want-to-fitssystemwindows-4e26d9ce1eec#.kpokdt33j)で取り上げられています。 – Sufian