2016-07-19 2 views
0

私の研究から以前に答えられた質問のように聞こえますが、私は解決策を見つけることができませんでした。私のレイアウトは、おおよそ以下の通りです:私のフラグメントの上にビューを維持する方法

enter image description here

メインエリアは、私がフラグメントを交換/追加しますコンテナである、と私は下のナビゲーションメニューを置く場所底があります。ピンクのビューは、私がメニューの上に置く必要があるボタンです(それは動作しません)。

メインビューにフラグメントを追加するたびに、TextViewがコンテナビューの後に追加されても、「メニュー」テキストが消えます。下のメニューコンテナの後に追加されるピンクのボタンと同じです(下のmy XMLを参照)。

「メニュー」TextViewとピンクのボタンの両方を常に私のフラグメントの上に置くにはどうしたらいいですか?

この

は私のxmlです:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="#eee" 
    tools:context="com.wecancer.wecancer.activities.Menu"> 

    <FrameLayout 
     android:id="@+id/main_container_view" 
     android:layout_width="match_parent" 
     android:layout_height="520dp" 
     android:layout_marginBottom="0dp" 
     > 
    </FrameLayout> 

    <TextView 
     android:id="@+id/main_center_tv" 
     android:layout_centerVertical="true" 
     android:textSize="24sp" 
     android:layout_centerHorizontal="true" 
     android:text="@string/menu" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" /> 

    <FrameLayout 
     android:layout_alignParentBottom="true" 
     android:id="@+id/main_bottom_menu_container" 
     android:layout_width="match_parent" 
     android:background="@color/lightGray" 
     android:layout_height="40dp" 
     > 

    </FrameLayout> 

    <Button 
     android:elevation="1dp" 
     android:id="@+id/menu_plus_img" 
     android:layout_centerHorizontal="true" 
     android:layout_alignParentBottom="true" 
     android:background="@color/colorAccent" 
     android:layout_width="70dp" 
     android:layout_marginBottom="0dp" 
     android:layout_height="70dp" 
     tools:targetApi="lollipop" /> 

</RelativeLayout> 

答えて

0

あなたはちょうどあなたがそうRelativeLayoutを必要としないでframeLayout

レイアウトの複雑さを利用しながら、レイアウト内のビューの順序を変更する必要があります切り替える必要があります。

+0

実用的な解決策をください。それは本当の答えではない、私は順序が正しいと言うと、あなたは "単に順序を変更する"と言って以来。 –

1

がThis`

<FrameLayout 
    android:layout_alignParentBottom="true" 
    android:id="@+id/main_bottom_menu_container" 
    android:layout_width="match_parent" 
    android:background="@color/colorPrimary" 
    android:layout_height="40dp" 
    > 

</FrameLayout> 

<Button 
    android:elevation="1dp" 
    android:id="@+id/menu_plus_img" 
    android:background="@color/colorAccent" 
    android:layout_width="70dp" 
    android:layout_height="70dp" 
    tools:targetApi="lollipop" 
    android:layout_marginLeft="71dp" 
    android:layout_marginStart="71dp" 
    android:layout_alignParentTop="true" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentStart="true" /> 

<TextView 
    android:id="@+id/main_center_tv" 
    android:textSize="24sp" 
    android:text="@string/menu" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_marginLeft="16dp" 
    android:layout_marginStart="16dp" 
    android:layout_alignBaseline="@+id/menu_plus_img" 
    android:layout_alignBottom="@+id/menu_plus_img" 
    android:layout_toRightOf="@+id/menu_plus_img" 
    android:layout_toEndOf="@+id/menu_plus_img" /> 

<FrameLayout 
    android:id="@+id/main_container_view" 
    android:layout_width="match_parent" 
    android:layout_height="520dp" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentStart="true" 
    android:layout_below="@+id/menu_plus_img"> 


</FrameLayout> 

`

+0

TextViewでは機能しましたが、ボタンでは機能しませんでしたが、なぜですか? TextViewがなぜトップになるのかについての説明を含めることができますか? –

+0

layout_centerHorizo​​ntal = "true"をテキストビューで使用しました。これは画面の中央に配置され、先頭に空のフレームレイアウトが表示されますが、フラグメントを読み込むとその下のテキストビューが非表示になります。 ボタンで直面している問題は何ですか? – Nofi

+0

私はこのライブラリhttps://github.com/roughike/BottomBarを使用していますが、明らかにプログラム的に要素を追加しています。だから私はビューを構築した後にbringToFront()を使用しても、私のボタンを前面に持っていくことはできません。 –

0

を試してみて、私は本当にbringToFrontbringChildToFrontなどの理由方法を知らない、またはそのインデックスを変更するには、ビューの子が機能しなかったの追加と削除します。だから私は実際に新しいレイアウト構造を作成しなければなりませんでした。私がやった

RelativeLayout 
...FrameLayout 
...TextView 
...FrameLayout 
...Button 

:代わりの

二RelativeLayoutはボタンのみと透明な背景を持っているのに対し

FrameLayout 
...RelativeLayout 
......FrameLayout 
......FrameLayout 
......TextView 
...RelativeLayout 
......Button 

。私の完全なXMLコードは参考のために以下にあります。

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

    <RelativeLayout 
     xmlns:tools="http://schemas.android.com/tools" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="#eee" 
     tools:context="com.wecancer.wecancer.activities.Menu"> 

     <FrameLayout 
      android:layout_alignParentBottom="true" 
      android:id="@+id/main_bottom_menu_container" 
      android:layout_width="match_parent" 
      android:background="@color/lightGray" 
      android:layout_height="wrap_content" /> 

     <FrameLayout 
      android:id="@+id/main_container_view" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_marginBottom="0dp" /> 

     <TextView 
      android:id="@+id/main_center_tv" 
      android:layout_centerVertical="true" 
      android:textSize="24sp" 
      android:layout_centerHorizontal="true" 
      android:text="@string/menu" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" /> 

    </RelativeLayout> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

     <Button 
      android:onClick="menuPlusBt" 
      android:elevation="5dp" 
      android:id="@+id/menu_plus_img" 
      android:layout_centerHorizontal="true" 
      android:layout_alignParentBottom="true" 
      android:background="@drawable/green_circle" 
      android:layout_width="70dp" 
      android:layout_marginBottom="0dp" 
      android:layout_height="70dp" 
      tools:targetApi="lollipop" /> 

    </RelativeLayout> 

</FrameLayout> 
関連する問題