2015-09-16 69 views
1

我想在列表視圖的末尾添加一個按鈕。我有以下的XML文件。列表視圖顯示其內容,但該按鈕不顯示。在ListView的末尾添加一個按鈕

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:minWidth="25px" 
    android:minHeight="25px"> 
    <ListView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:id="@+id/myListView" /> 
    <Button 
     android:text="Project Download" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/download" /> 
</LinearLayout> 
+0

研究的RelativeLayout – MobileMon

回答

3

問題是您的ListView中的屬性android:layout_height="match_parent"match_parent意味着listview將填充所有空間。正確的方法是:不顯示

<?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:minWidth="25px" 
    android:minHeight="25px"> 
    <ListView 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:weight="1" 
     android:id="@+id/myListView" /> 
    <Button 
     android:text="Project Download" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/download" /> 
</LinearLayout> 
0
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:minWidth="25px" 
android:minHeight="25px"> 

<Button 
    android:layout_alignParentBottom="true" 
    android:text="Project Download" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:id="@+id/download" /> 

<ListView 
    android:layout_above="@id/download" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:id="@+id/myListView" /></RelativeLayout> 
1

你的按鈕,因爲你的ListView把整個空間隱藏你的按鈕,設置它的layout_heightmatch_parentmatch_parent將佔用整個可用空間。因此,將其更改爲WRAP_CONTENT這樣的:

<?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:minWidth="25px" 
    android:minHeight="25px"> 
    <ListView 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_parent" 
     android:id="@+id/myListView" /> 
    <Button 
     android:text="Project Download" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/download" /> 
</LinearLayout> 

WRAP_CONTENT將包裹你​​的看法,以最小的可用高度/寬度不隱藏任何東西,或做什麼不清楚的地方。

1

我有同樣的問題,並解決。 你只需要換行佈局成滾動型

<ScrollView 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" > 

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

      <android.support.v7.widget.RecyclerView 
       android:id="@+id/rv_transaction_history" 
       android:layout_width="match_parent" 
       android:layout_height="0dp" 
       android:layout_weight="1"> 

      </android.support.v7.widget.RecyclerView> 

      <Button 
       android:id="@+id/btn_history_load_more" 
       style="?borderlessButtonStyle" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:fontFamily="sans-serif-medium" 
       android:paddingBottom="@dimen/margin_big" 
       android:paddingTop="@dimen/margin_large" 
       android:text="@string/text_btn_load_more" 
       android:textColor="#009CDE" 
       android:textSize="@dimen/text_size_medium" /> 
    </LinearLayout> 
</ScrollView> 
相關問題