如何将listView的高度调整为其下的片段

时间:2017-01-16 17:07:06

标签: android listview fragment

我有一个Activity,其中包含ExpandableListView隐藏Fragment。当您单击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>

1 个答案:

答案 0 :(得分:0)

终于找到了解决方案!诀窍是你只需要将容器与父底部对齐,然后将listView的高度设置为let allMainShape = [blueSquareObject, blueCircleObject] //Gives you `[ShapeColour]` //Now get random object from it. let randomIndex = Int(arc4random_uniform(UInt32(allMainShape.count))) print"Colour is \(allMainShape[randomIndex].color)" 并将其放在容器上方。由于listView占用了所有可能的高度,但仍然必须高于容器,因此当容器中出现片段时,它会自动缩小。

match_parent