2016-08-08 23 views
0

Mein Layout funktioniert gut, es hat einen Elternteil Linear Layout und mehrere Linear Layouts drin.Lineares Layout innerhalb des Frame Layout funktioniert nicht mehr

Jetzt muss ich ein Hintergrundbild hinzufügen, so dass ich hier ein Rahmenlayout hinzufügen muss.

Wenn ich Eltern Linear Layout zu Frame Layout ändern, verschwinden alle Elemente in der linear layout. Wenn ich Frame Layout hinzufüge, verschwinden in Linear Layout alle Elemente im linearen Layout.

Ich kann nicht verstehen, wie man ein Rahmenlayout legt, ohne lineare Layoutelemente zu entfernen.

Der Layoutcode ist ziemlich lang.

Ich setze oben einen Teil davon.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    > 


    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="6" 
     android:orientation="vertical" 
     > 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="80dp" 
      android:orientation="horizontal" 
      android:layout_marginTop="20dp" 
      android:layout_marginLeft="30dp" 
      android:layout_marginRight="30dp" 
      > 

      <ImageView 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_weight="0.8" 
       android:src="@drawable/image11" 
       /> 

      <LinearLayout 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
       android:orientation="vertical" 
       android:paddingTop="10dp" 

       > 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:text="7:00 PM CST" 
       android:layout_gravity="center" 
       android:gravity="center" 
       android:textColor="@color/white" 
       android:fontFamily="sans-serif-medium" 
       android:textSize="12sp" 
       /> 

     </LinearLayout> 

     <ImageView 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="0.8" 
      android:src="@drawable/icon2" 
      /> 

    </LinearLayout> 





    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="40dp" 
     android:orientation="horizontal" 
     android:paddingLeft="20dp" 
     android:paddingRight="20dp" 
     > 


     <LinearLayout 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_weight="4" 
      android:orientation="vertical" 
      android:background="@drawable/cart_custom_background" 
      android:paddingBottom="2dp" 
      > 

      <LinearLayout 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:layout_weight="4" 
       android:orientation="horizontal" 
       android:layout_marginRight="1dp" 
       android:layout_marginLeft="1dp" 
       > 
+0

Versuchen Sie Relative Layout anstelle von Frame-Layout – Dnyanesh

+0

Dank @Dnyanesh, wenn ich "Eltern Layout" auf "Relative Layout" ändern, verschwinden alle Elemente – Kirmani88

+0

Sind Sie sicher, Ihre Layout_Height/Layout_Width sind nicht gleich 0 dp innerhalb der framelayout ? –

Antwort

1

Jetzt brauche ich ein Hintergrundbild hinzuzufügen, so dass ich hier einen Rahmen Layout hinzufügen müssen.

Sie müssen kein weiteres Layout hinzufügen, um den Hintergrund zu erhalten. Ihre Wurzel (oder auch jede andere) <LinearLayout> sollte genug sein. Sie können den Hintergrund gesetzt werden:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@drawable/my_drawable" > // Can also give color here 

Wenn ich Eltern Linear-Layout ändern Layout Rahmen, es alle die Elemente in der linearen Layout verschwindet.

Das ist in erster Linie, weil die <FrameLayout> im Gegensatz zu <LinearLayout> Zugabe gehalten alle Kinder auf der jeweils anderen.