2016-08-08 29 views
0

我的佈局工作正常,它內部有一個父項Linear Layout和多個Linear Layouts框架佈局內部的線性佈局停止工作

現在我需要添加一個背景圖像,所以我需要在這裏添加一個框架佈局。

當我將父母Linear Layout更改爲Frame Layout時,它將消失linear layout中的所有項目。

如果我加Frame Layout,在Linear Layout裏面,它會消失線性佈局中的所有項目。

我無法理解如何在不移除線性佈局項目的情況下放置框架佈局。

佈局代碼很長。

我把以上的一部分。

<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

嘗試相對佈局,而不是框架佈局 – Dnyanesh

+0

謝謝@Dnyanesh,當我將'父佈局'改爲'相對佈局'時,所有元素消失 – Kirmani88

+0

您確定您的layout_height/layout_width不等於幀佈局中的0 dp ? –

回答

1

現在我需要添加背景圖片,所以我需要在這裏添加邊框 佈局。

您不需要添加另一個佈局來提供背景。你的根(或者任何其他)<LinearLayout>應該足夠了。您可以通過設置背景:

<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 

當我改變父線性佈局到框架佈局,消失在線性佈局中的所有 項目。

這主要是因爲<FrameLayout>不像<LinearLayout>不斷增加所有的孩子在彼此之上。