2017-01-10 5 views
0

レイヤウィジェットのトピックに関するほぼすべての記事が、FrameLayoutsにつながります.FrameLayoutsは、XMLの出現順序に従ってスタックすることになっています。テストするために、ボタンとTextViewをxmlに入れ、TextViewがボタンと重なっていることを確認します。ボタンがテキストビューの前後に配置されているかどうかは関係ありません。ボタンは常に上に表示されます。誰かが私が間違っているのを見ることができますか?アンドロイド:FrameLayoutのボタン上にテキストビューのスタックがない理由

<?xml version="1.0" encoding="utf-8"?> 
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/activity_main" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context="com.jdot.testloadingfragments.MainActivity"> 

    <Button 
     android:id="@+id/btn_test" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginStart="10dp" 
     android:text="  " 
     /> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="10dp" 
     android:text="----------------------------------------------------------"/> 


</FrameLayout> 

答えて

3

のTextViewにelevationを追加すると、それはここButton

例えば

<?xml version="1.0" encoding="utf-8"?> 
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/activity_main" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context="com.jdot.testloadingfragments.MainActivity"> 

    <Button 
     android:id="@+id/btn_test" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginStart="10dp" 
     android:text="  "/> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="10dp" 
     android:elevation="2dp" 
     android:text="----------------------------------------------------------"/> 
</FrameLayout> 

詳細情報の上に表示されようになります:Why is the framelayout not drawing z index correctly?

+0

ありがとう

。私は標高を避けていますが、ボタンが特殊なケースであることを知らなかった。 AppCompatには、共通のデザイン要素に最新のAPIレベルを使用させるテーマがあります。 –

0

でframeLayoutは、理想的には単一の項目を表示するために使用されます。

複数の子ビューをフレームレイアウトに表示する場合は、各子とandroid:layout_gravity属性を使用して重複させずに正しく配置し、ビューを重複させたい場合は標高を使用してみます。より多くの情報 訪問https://developer.android.com/reference/android/widget/FrameLayout.html

+0

高度について知っていますが、アプリをAPIに制限することはできません21 + –

+0

** app:elevation **属性を使用してその制限を乗り越えるようにしてください。 –

+0

ありがとう、それは情報の有用なビットです! –

関連する問題