2012-12-05 43 views
-1

這裏是我的活動XML的佈局:無法看到一個ListView下一個按鈕,在我的佈局

enter image description here

出於某種原因,我無法看到按鈕t我的屏幕的底部。 下面的代碼:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@drawable/app_bg" 
    android:orientation="vertical" >  

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" > 

    <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:background="@drawable/bg_transparent" 
     android:orientation="vertical" 
     android:minHeight="44dip" 
     android:minWidth="44dip" > 

     <TextView 
      android:id="@+id/lblNotesCount" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center_horizontal" 
      android:textSize="18sp" 
      android:textStyle="bold" 
      android:textColor="@color/lblNotesCountColor" /> 

     <TextView 
      android:id="@+id/lblTxtNotes" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center_horizontal" 
      android:textSize="14sp" 
      android:textStyle="bold" 
      android:textColor="@color/lblNotesCountColor" /> 
    </LinearLayout> 


    <TextView 
     android:id="@+id/txtActivityListByCategory_Header" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:ellipsize="end" 
     android:gravity="center_vertical|center_horizontal" 
     android:paddingLeft="2dp" 
     android:singleLine="true" 
     android:textStyle="bold" 
     android:textColor="@color/color_WHITE" /> 

    <Button 
     android:id="@+id/btnAddNote" 
     style="?android:attr/buttonStyleSmall" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:background="@drawable/btn_new_note_selector" 
     android:minHeight="44dip" 
     android:minWidth="44dip" /> 
</LinearLayout> 

<TextView 
    android:id="@+id/emptyList" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:paddingLeft="2dp" 
    android:text="@string/txtEmptyList" 
    android:textAppearance="?android:attr/textAppearanceMedium" 
    android:textColor="@color/emptyList" /> 

<ListView 
    android:id="@+id/lstNotesByCategory" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:drawSelectorOnTop="false" > 
</ListView> 


<Button 
    android:id="@+id/btnaBack" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/btnBack" /> 

我試圖把在一個單獨的LinearLayout底部的TextView和ListView,我試着給那個按鈕layout_weight - 沒有任何幫助,我還沒有看到這個按鈕,LinearLayout一直進行到活動的底部。

這裏有什麼問題?爲什麼我看不到那個按鈕?

編輯:寫下整個XML代碼

+4

可以爲您提供整個佈局XML? –

+0

嘗試在滾動視圖中放置佈局 –

+0

我假設您忘記複製/粘貼關閉標記?如果你讓這個按鈕有一個靜態尺寸,比如android:layout_height =「50dp」,寬度可能相同。 – NickL

回答

9

製作你的ListView的android:layout_height="0dp"android:layout_weight="1"

像這樣:

<ListView 
    android:id="@+id/lstNotesByCategory" 
    android:layout_width="wrap_content" 
    android:layout_height="0dp" 
    android:layout_weight="1" 
    android:drawSelectorOnTop="false" > 
</ListView> 

<Button 
    android:id="@+id/btnaBack" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/btnBack" /> 

這會讓你的ListView垂直擴展,直到你的按鈕的邊框。

希望這有助於

+0

這實際上工作!非常感謝你!我試圖在以前的嘗試中將android:layout_weight =「1」應用於按鈕......現在它工作得很好!再次感謝! – Igal

+0

@ Murat Nafiz有趣的解決方案,+1。 :) –

1

修正你的ListView的高度

<ListView 
    android:id="@+id/lstNotesByCategory" 
    android:layout_width="wrap_content" 
    android:layout_height="height you want to give to list" 
    android:drawSelectorOnTop="false" > 
</ListView> 

<ListView 
     android:id="@+id/lstNotesByCategory" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:drawSelectorOnTop="false" 
     android:layout_above="@id/btnaBack"> 
    </ListView> 

嘗試使用此代碼,這將幫助你

+0

第二個解決方案很好。+ 1。 –

+2

@Ravinder'android:layout_above'對'LinearLayout'沒有幫助 –

+0

android:layout_above在LinearLayout中不受支持 –

0

試試這個它可以幫助您瞭解如何使用Layou_weight

<TextView 
    android:id="@+id/emptyList" 
    android:layout_width="wrap_content" 
    android:layout_height="0dp" 
    android:layout_weight="2" 
    android:paddingLeft="2dp" 
    android:text="txtEmptyListsss" 
    android:textAppearance="?android:attr/textAppearanceMedium" 
    android:textColor="#ffffff" /> 

<ListView 
    android:id="@+id/lstNotesByCategory" 
    android:layout_width="wrap_content" 
    android:layout_height="0dp" 
    android:layout_weight="6" 
    android:drawSelectorOnTop="false" > 
</ListView> 

<Button 
    android:id="@+id/btnaBack" 
    android:layout_height="0dp" 
    android:layout_weight="2" 
    android:layout_width="fill_parent" 
    android:text="btnBack" /> 

    </LinearLayout> 
+0

嘗試什麼???????? – Deepzz

1

1>與高度「包裝內容」 使用回收鑑於此鏈接是 https://gist.github.com/AnderWeb/1eb97efb9963171c42bb

2>把按鈕波紋管RecycleView。

第二種解決 以相對佈局父佈局 添加按鈕和列表視圖上相對佈局 按鈕應該父底部真正

列表視圖如果你上面的按鈕的

相關問題