を削除します。 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. は、私はこのレイアウトを持っている別の要素
- 5. は、私は私のメインインデックスビューでこれらのActionLinksを持って
- 6. タグ私はこれを持って
- 7. タブバーdidSelectItemは、私がこれを持って私のヘッダファイルで
- 8. 私は私のコードでこれを持って<%= for %>ビューヘルパー
- 9. 私は私のモデルでこれを持って
- 10. 私はこれ持ってArrayListの
- 11. レールは3分content_forは、私はこれを持っていレイアウト(application.html)を持っている
- 12. は、私はこのコードを持って
- 13. は、私はこのコードを持って
- 14. モーダルビューは、私は私のMainViewControllerでこのメソッドを持って
- 15. ハウツー要素はこれまでのところ、私はこのレイアウトのコードを持って
- 16. 私のリターン機能は、私はこれを持って私のjQueryのAJAX
- 17. IE7インラインブロックのトリックは、私がここにレイアウトを持っている
- 18. Javascriptを:Firefoxのアドオンは、私はこれを持って私のbutton.xulファイルで
- 19. 私はこのIEnumerableを持ってIEnumerable
- 20. 私は、この氷を持って
- 21. は、私がこのXSLを持って
- 22. Railsは、私は私のコントローラでこれを持っているのparams
- 23. ハンドルバーは、私は私のハンドルテンプレートでこれを持っているJavaScriptの
- 24. 私は私のコードでこの行を持っている
- 25. 私のSQLクエリは、私は、このクラスを持っている
- 26. Androidのは、私がこのようなレイアウトを持つレイアウト
- 27. jQuery.ajaxSetupは()私はこれを持っているJSファイルで
- 28. 私は、このbashのファイル持って
- 29. ルビー - 私はこのルートを持っている私は、テンプレート
- 30. は、私はこれを持ってjQueryのまたはJavaScript
この記事は、[なぜ私はfitsSystemWindowsになりたいのですか?](https://medium.com/google-developers/why-would-i-want-to-fitssystemwindows-4e26d9ce1eec#.kpokdt33j)で取り上げられています。 – Sufian