2017-11-30 5 views
1

FrameLayout内でLinearLayoutを作成していますが、LinearLayoutはFrameLayoutの中央に配置する必要があります。 FrameLayoutが650dpを超え、LinearLayoutの幅を650dpに設定すると、線形レイアウトの左右に余裕ができます。親が650dpを超える場合、Linearlayoutの幅を650dpにする、そうでない場合は親を一致させる

親FrameLayoutが650dp未満の場合は、親線に合わせて線幅を設定します。

親のFrameLayoutの幅が向きの変更に応じて変化するため、OnLayoutChangeListener、OnGlobalLayoutListener、OnAttachStateChangeListenerを使用して、画面の回転後の幅を検出しようとしましたが、いずれも機能しません。

親ビューの幅を見つけようとすると正しい軌道に乗っていますか?

または、ConstraintLayoutとして親ビューを使用し、可能な場合は650内のLinearLayoutを作成し、幅が足りない場合は親に展開できますか?

(親ビューは必ずしも画面全体を占有するとは限らないため、sw600またはsw600-landなどの異なるレイアウトresフォルダでは異なる値を使用することはできません)。

+1

'ConstraintLayout'の子(' CoordinatorLayout'ではなく)は 'app:layout_constraintWidth_max '。 –

答えて

1

これを処理する適切な方法は、別のレイアウトファイルをlayout-landの下に作成し、そのために650dpの幅を使用することです。また、異なる画面のサポートの詳細についてはsee the official training hereを参照してください。

+0

問題は、画面幅をparentViewの幅と同じにすることはできないということです。たとえば、parentframeLayoutはタブレットの2つの列のいずれかにある可能性があります。この場合、screenwidthがsw720であっても、私はまだそれを親にマッチさせる必要があるかもしれません。 –

+0

まだ、あなたがwidth修飾子について述べたのと同じロジックを適用できます。つまり、新しい 'styles.xml'を作成して650dp幅の修飾子を与え、そこに線形レイアウトの幅を定義することになります。 上記の同じリンクで幅の異なるスタイルを作成する方法は間違いなくあります。 –

+0

sw720で650のスタイルを定義し、720幅の画面で2列のビューを表示すると、その列の幅は300dpになります。その場合、650に設定すると画面が画面より広くなります –

0

興味のある方は、私はEugenのコメントごとにConstraintLayoutで解決しました。これは、のLinearLayoutの幅が小さな画面(< 650dp)で親と一致することを確認し、大きな画面で650dpする幅をキャップ

<?xml version="1.0" encoding="utf-8"?> 
<android.support.constraint.ConstraintLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"> 

    <LinearLayout 
     android:id="@+id/row_content" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" 
     app:layout_constraintEnd_toEndOf="parent" 
     app:layout_constraintStart_toStartOf="parent" 
     app:layout_constraintWidth_max="650dp"/> 
</android.support.constraint.ConstraintLayout> 
0
<LinearLayout 
    android:layout_width="300dp" 
    android:layout_height="100dp" 
    android:background="#f00" 
    > 

    <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:maxWidth="200dp" 
     android:minWidth="200dp" 
     android:background="#00f" 
     > 
    </LinearLayout> 
</LinearLayout> 

enter image description here

の検索結果をサイズになるとき、親幅= 150DP型

enter image description here

関連する問題