2016-11-10 72 views
0

我有一個列表視圖下面的LinearLayout的問題。我試圖給上面的listview權重和佈局,將layout_height設置爲0dp,但沒有任何變化。ListView下面的線性佈局,有些部分不可見?

這裏是我的XML代碼:

<?xml version="1.0" encoding="utf-8"?> 
<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:orientation="horizontal" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:weightSum="100" 
     android:background="#00c4ff"> 
     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Application № - " 
      android:layout_weight="50"/> 
     <TextView 
      android:id="@+id/number" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="__" 
      android:layout_weight="20" /> 
     <EditText 
      android:id="@+id/date" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:inputType="date" 
      android:hint="dd/mm/yyyy" 
      android:layout_weight="30" 
      /> 
     </LinearLayout> 

      <ListView 
       android:id="@+id/lvMain" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content"> 
      </ListView> 


    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical" 
     android:gravity="bottom" 
     android:id="@+id/ll"> 
     <Button 
      android:id="@+id/plus" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Add"/> 
     <EditText 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:id="@+id/comment" 
      android:inputType="text" 
      android:hint="Comment" /> 
     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:orientation="horizontal" 
      android:gravity="bottom"> 
      <Button 
       android:id="@+id/send" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Send" /> 
      <Button 
       android:id="@+id/close" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Save and close"/> 
     </LinearLayout> 

    </LinearLayout> 


</LinearLayout> 

時的ListView填滿整個屏幕,我看不到下面給它的按鈕。

回答

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

    <LinearLayout android:orientation="horizontal" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:weightSum="100" 
     android:background="#00c4ff"> 
     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Application № - " 
      android:layout_weight="50"/> 
     <TextView 
      android:id="@+id/number" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="__" 
      android:layout_weight="20" /> 
     <EditText 
      android:id="@+id/date" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:inputType="date" 
      android:hint="dd/mm/yyyy" 
      android:layout_weight="30" /> 
    </LinearLayout> 

    <ListView 
     android:id="@+id/lvMain" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="90"> 
    </ListView> 


    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="10" 
     android:orientation="vertical" 
     android:gravity="bottom" 
     android:id="@+id/ll"> 
     <Button 
      android:id="@+id/plus" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:text="Add"/> 
     <EditText 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:id="@+id/comment" 
      android:inputType="text" 
      android:hint="Comment" /> 
     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:orientation="horizontal" 
      android:gravity="bottom"> 
      <Button 
       android:id="@+id/send" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Send" /> 
      <Button 
       android:id="@+id/close" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Save and close"/> 
     </LinearLayout> 

    </LinearLayout> 


</LinearLayout> 
+0

還請解釋你是如何解決這個問題的。只有代碼答案沒有幫助。 – Doomsknight

+0

方法佈局 - 權重和權重總和是解決這個問題的方法。但在提出這樣的問題之前請嘗試,並且不要問這樣的直接問題 –

+0

哦,你是個天才,非常感謝你 – Sanzhar

0

如下

<?xml version="1.0" encoding="utf-8"?> 
<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:orientation="horizontal" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="#00c4ff"> 
     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Application № - " 
      android:layout_weight="50"/> 
     <TextView 
      android:id="@+id/number" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="__" 
      android:layout_weight="20" /> 
     <EditText 
      android:id="@+id/date" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:inputType="date" 
      android:hint="dd/mm/yyyy" 
      android:layout_weight="30" 
      /> 
    </LinearLayout> 

    <ListView 
     android:id="@+id/lvMain" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1"> 
    </ListView> 


    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical" 
     android:gravity="bottom" 
     android:id="@+id/ll"> 
     <Button 
      android:id="@+id/plus" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Add"/> 
     <EditText 
      android:layout_width="match_parent" 
      android:layout_height="50dp" 
      android:id="@+id/comment" 
      android:inputType="text" 
      android:hint="Comment" /> 
     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="horizontal" 
      android:gravity="bottom"> 
      <Button 
       android:id="@+id/send" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Send" /> 
      <Button 
       android:id="@+id/close" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Save and close"/> 
     </LinearLayout> 

    </LinearLayout> 


</LinearLayout> 
+0

另請說明您是如何解決問題的。只有代碼答案沒有幫助。 – Doomsknight

1
<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <LinearLayout 
android:id="@+id/topLayout" 
android:orientation="horizontal" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
android:alignParentTop="true" 
     android:weightSum="100" 
     android:background="#00c4ff"> 
     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Application № - " 
      android:layout_weight="50"/> 
     <TextView 
      android:id="@+id/number" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="__" 
      android:layout_weight="20" /> 
     <EditText 
      android:id="@+id/date" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:inputType="date" 
      android:hint="dd/mm/yyyy" 
      android:layout_weight="30" 
      /> 
     </LinearLayout> 

    <LinearLayout 
android:id="@+id/bottomLayout" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical" 
     android:gravity="bottom" 
android:alignParentBottom="true" 
     android:id="@+id/ll"> 
     <Button 
      android:id="@+id/plus" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Add"/> 
     <EditText 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:id="@+id/comment" 
      android:inputType="text" 
      android:hint="Comment" /> 
     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:orientation="horizontal" 
      android:gravity="bottom"> 
      <Button 
       android:id="@+id/send" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Send" /> 
      <Button 
       android:id="@+id/close" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Save and close"/> 
     </LinearLayout> 

    </LinearLayout> 

      <ListView 
       android:id="@+id/lvMain" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
android:layout_below="@+id/topLayout" 
android:layout_above="@+id/bottomLayout"> 
      </ListView> 

</RelativeLayout> 

編輯了自己的代碼更改。嘗試這個。

在這裏我使用了RelativeLayout,所以我們使用android:alignParentBottom="true"作爲底部佈局,使得佈局固定在底部。 Simillarly我們可以使用android:alignParentBottom="true"進行頂層佈局。現在來ListView,這是我們需要的頂部和底部之間佈局的地方我用下面的代碼來實現它

android:layout_below="@+id/topLayout" 
    android:layout_above="@+id/bottomLayout" 

這使得ListView頂部和底部之間的佈局堅持英寸

希望這是有益:)

+0

也請解釋您是如何解決問題的。只有代碼答案沒有幫助。 – Doomsknight

+1

@Doomsknight:看我給出了代碼:) – Jeevanandhan

1

您的佈局,加入佈局權重編輯。請檢查。

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

    <LinearLayout android:orientation="horizontal" 
        android:layout_width="match_parent" 
        android:layout_height="0dp" 
        android:layout_weight="0.1" 
        android:weightSum="100" 
        android:background="#00c4ff"> 
     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Application № - " 
      android:layout_weight="50"/> 
     <TextView 
      android:id="@+id/number" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="__" 
      android:layout_weight="20" /> 
     <EditText 
      android:id="@+id/date" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:inputType="date" 
      android:hint="dd/mm/yyyy" 
      android:layout_weight="30" 
      /> 
    </LinearLayout> 

    <ListView 
     android:id="@+id/lvMain" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="0.6"> 
    </ListView> 


    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:orientation="vertical" 
     android:layout_weight="0.3" 
     android:gravity="bottom" 
     android:id="@+id/ll"> 
     <Button 
      android:id="@+id/plus" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Add"/> 
     <EditText 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:id="@+id/comment" 
      android:inputType="text" 
      android:hint="Comment" /> 
     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:orientation="horizontal" 
      android:gravity="bottom"> 
      <Button 
       android:id="@+id/send" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Send" /> 
      <Button 
       android:id="@+id/close" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Save and close"/> 
     </LinearLayout> 

    </LinearLayout> 


</LinearLayout> 
+0

謝謝你我試過你的代碼,它沒有工作,我不能看到listview在所有 – Sanzhar

1

你應該嘗試列表視圖與佈局有重量。

示例代碼:

<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:orientation="horizontal" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="0.3" 
     /> 

<LinearLayout android:orientation="horizontal" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="0.4" 
     > 
<ListView 
       android:id="@+id/lvMain" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content"> 
      </ListView> 
</LinearLayout> 

<LinearLayout android:orientation="horizontal" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="0.3" 
     /> 

</LinearLayout> 

在此您的高度是固定的列表視圖。假設你可以使用列表視圖作爲可滾動的特定高度。

+0

謝謝,但它沒有工作,現在我不能看到在所有的列表視圖 – Sanzhar