2017-01-16 15 views
0

我有一個ActivityExpandableListView和隱藏Fragment它下面。當你點擊一個ListView的子元素時,片段變得可見並且從平滑的動畫的底部出現。問題是當出現片段時,它與列表的一部分重疊,所以我看不到底部的元素。爲了解決這個問題,我假設我可以在彈出片段的同時調整listView的高度,但我不知道該怎麼做。任何想法將不勝感激。如何調整listView的高度到它下面的一個片段

下面是什麼它顯示片段之前,看起來像一個例子:

enter image description here

而這正是發生後,(我不能下來了滾動):

enter image description here

這裏的佈局:

<RelativeLayout xmlns: 
    android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@drawable/main_background" 
    android:orientation="vertical"> 

<ExpandableListView 
    android:id="@+id/listView" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:choiceMode="singleChoice" 
    android:divider="@drawable/list_divider" 
    android:dividerHeight="1dp" 
    android:childDivider="@drawable/list_divider" 
    android:fontFamily="sans-serif-thin" 
    android:groupIndicator="@null" /> 

<FrameLayout 
    android:id="@+id/musicBarContainer" 
    android:layout_width="match_parent" 
    android:layout_height="150dp" 
    android:layout_alignParentBottom="true" 
    android:clickable="true" 
    android:fontFamily="sans-serif-thin" /> 
</RelativeLayout> 

回答

0

終於找到了解決辦法!訣竅是你只需要將容器對齊到父級底部,然後將你的listView的高度設置爲match_parent並將其放在容器上方。由於listView佔用了所有可能的高度,但仍然必須位於容器上方,因此當容器中出現碎片時它會自動縮小。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:background="@drawable/main_background" 
android:orientation="vertical"> 

    <FrameLayout 
     android:id="@+id/musicBarContainer" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:clickable="true" 
     android:fontFamily="sans-serif-thin" /> 

    <ExpandableListView 
     android:id="@+id/listView" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_above="@id/musicBarContainer" 
     android:childDivider="@drawable/list_divider" 
     android:choiceMode="singleChoice" 
     android:divider="@drawable/list_divider" 
     android:dividerHeight="1dp" 
     android:fontFamily="sans-serif-thin" 
     android:groupIndicator="@null" /> 
</RelativeLayout> 
相關問題