2016-03-16 39 views
2
<LinearLayout 
    android:id="@+id/linID" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" 
    android:layout_marginTop="20dp" 
    android:layout_marginLeft="30dp" 
    android:layout_marginRight="50dp" 
    android:layout_marginBottom="40dp"> 
    <TextView 
     android:layout_width="fill_parent" 
     android:layout_height="37dp" 
     android:background="@color/transparentBlack" 
     android:clickable="false" 
     android:id="@+id/gHeader" 
     android:textSize="22dp" 
     android:textColor="@color/homeCategoryTitleColor"/> 
    <ListView android:id="@id/android:list" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:headerDividersEnabled="false" 
     android:drawSelectorOnTop="true" 
     android:choiceMode="singleChoice" 
     android:clickable="false" 
     android:divider="@color/categorylist_divider" 
     android:dividerHeight="20.0sp" 
     android:layout_below="@+id/gHeader" 
     android:scrollbarSize="10dp" 
     android:fadeScrollbars="false"/> 
    <ImageView 
     android:layout_width="fill_parent" 
     android:layout_height="20dp" 
     android:background="@color/transparentBlack" 
     android_layout_below="@+id/android:list" 
     android:src="@drawable/down_arrow" /> 
</LinearLayout> 

這就是我到目前爲止的情況。 listview中的數據動態添加,出於某種原因,imageview始終位於屏幕的底部,除非listview將所有內容填滿,這顯示正常。有想法該怎麼解決這個嗎?我嘗試了多種方式,將佈局包裹起來以結合其他佈局來解決問題,但無法獲得創意。提前致謝!在列表視圖下方添加圖片

+0

'android_layout_below'只適用於RelativeLayout,並且使用'@ + id',除非你是**添加**一個id。引用時只能使用'@ id'。 –

+0

@Taeyoung李沒有得到你想要的?請參閱這裏它可能會幫助你: - http://coderzpassion.com/android-working-linearlayout/ –

+0

@jagjitsingh我想在listview下面添加圖像頁腳。我已經在listview上實現了imageview,但似乎無法弄清楚如何在它下面添加。有一個空間,我認爲它來自我在列表視圖上設置的高度。有任何想法嗎? –

回答

0

您可以使用

'com.android.support:percent:23.2.0'

庫成功地實現這一目標。您可以指定與HTML中相同的百分比。

<android.support.percent.PercentRelativeLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
xmlns:app="http://schemas.android.com/apk/res-auto"> 

<ListView android:id="@id/android:list" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:headerDividersEnabled="false" 
    android:drawSelectorOnTop="true" 
    android:choiceMode="singleChoice" 
    android:clickable="false" 
    android:divider="@color/categorylist_divider" 
    android:dividerHeight="20.0sp" 
    android:layout_below="@+id/gHeader" 
    android:scrollbarSize="10dp" 
    app:layout_hightPercent="70%" 
    android:fadeScrollbars="false"/> 
<ImageView 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    app:layout_hightPercent="30%" 
    android:background="@color/transparentBlack" 
    android_layout_below="@id/android:list" 
    android:src="@drawable/down_arrow" /> 

</android.support.percent.PercentRelativeLayout> 
+0

很酷,我會試試看,如果沒有其他解決方案出現了。謝謝! –

+0

@Taeyoung請高興 – UMESH0492

0

而不是android_layout_below在您的ListView中使用layout_weight。 這是應該的樣子:

<LinearLayout 
    android:id="@+id/linID" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" 
    android:layout_marginTop="20dp" 
    android:layout_marginLeft="30dp" 
    android:layout_marginRight="50dp" 
    android:layout_marginBottom="40dp"> 
    <TextView 
     android:layout_width="fill_parent" 
     android:layout_height="37dp" 
     android:background="@color/transparentBlack" 
     android:clickable="false" 
     android:id="@+id/gHeader" 
     android:textSize="22dp" 
     android:textColor="@color/homeCategoryTitleColor"/> 
    <ListView android:id="@id/android:list" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1"  
     android:headerDividersEnabled="false" 
     android:drawSelectorOnTop="true" 
     android:choiceMode="singleChoice" 
     android:clickable="false" 
     android:divider="@color/categorylist_divider" 
     android:dividerHeight="20.0sp" 
     android:layout_below="@+id/gHeader" 
     android:scrollbarSize="10dp" 
     android:fadeScrollbars="false"/> 
     <ImageView 
      android:layout_width="fill_parent" 
      android:layout_height="20dp" 
      android:background="@color/transparentBlack" 
      android:src="@drawable/down_arrow" /> 
</LinearLayout> 

希望這有助於!

+0

嘿,謝謝你的回答。這是我所做的一個嘗試,在肖像模式下看起來很棒,但在橫向模式下看起來不錯。在風景中,它不顯示圖像,只是列表。任何想法如何解決這個問題?或者你知道如何以編程方式改變佈局的權重,如listview/imageview? –

+0

好吧,我會編輯我的答案,只是使用layout_weight –

+0

Woah,我的意思是說給你,而不是上面的人,但這段代碼的作品令人驚歎。 –