【问题标题】:Scrolling & Layout Problems with ExpandableListViewExpandableListView 的滚动和布局问题
【发布时间】:2013-10-05 16:05:12
【问题描述】:

我正在开发一个应用程序,它需要在顶部有一个不可滚动的页眉,在中间需要一个可滚动的ExpandableListView,然后在底部有一个不可滚动的页脚。见下图

问题是ExpandableListView 的可滚动属性,当我展开ExpandableListView 的父视图时,在页脚下滚动列表,无法滚动,这就是问题所在。见下文

这是xml

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

<include
    android:id="@+id/callheader"
    android:layout_alignParentTop="true"
    layout="@layout/callerheader" />

<ExpandableListView
    android:id="@+id/exSavedVoiceList"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@+id/callheader"
    android:groupIndicator="@drawable/drawableanimation"
    android:paddingLeft="10dp" >
</ExpandableListView>

<LinearLayout
    android:id="@+id/llbottom"
    android:layout_width="match_parent"
    android:layout_height="50sp"
    android:layout_alignParentBottom="true"
    android:layout_alignParentRight="true"
    android:background="#ff33b5e5"
    android:gravity="center"
    android:orientation="vertical" >

    <Button
        android:id="@+id/bSaveNewVoice"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="#ff33b5e5"
        android:contentDescription="@string/add_new"
        android:drawableLeft="@drawable/setting"
        android:drawablePadding="40dp"
        android:text="@string/add_new"
        android:textColor="#FFFFFF"
        android:textSize="25sp" />
</LinearLayout>

如果我将android:layout_below="@+id/exSavedVoiceList" 放入llbottom (LinearLayout),如果parent view 展开,页脚将移到下方。

请提供一个可能的解释的解决方案。

【问题讨论】:

    标签: android xml android-layout scrollview expandablelistview


    【解决方案1】:
    // try this
    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:background="#F2B1DBF3"
                    android:orientation="vertical" >
        <include
                android:id="@+id/callheader"
                layout="@layout/callerheader" />
    
        <ExpandableListView
                android:id="@+id/exSavedVoiceList"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="1"
                android:layout_below="@+id/callheader"
                android:groupIndicator="@drawable/drawableanimation"
                android:paddingLeft="10dp"/>
    
        <LinearLayout
                android:id="@+id/llbottom"
                android:layout_width="match_parent"
                android:layout_height="50dp"
                android:background="#ff33b5e5"
                android:gravity="center"
                android:orientation="vertical" >
    
            <Button
                    android:id="@+id/bSaveNewVoice"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:background="#ff33b5e5"
                    android:contentDescription="@string/add_new"
                    android:drawableLeft="@drawable/setting"
                    android:drawablePadding="40dp"
                    android:text="@string/add_new"
                    android:textColor="#FFFFFF"
                    android:textSize="25sp" />
        </LinearLayout>
    </LinearLayout>
    

    【讨论】:

    • 工作得很好,但你能告诉我RelativeLayout有什么问题
    • 如果我们有 LinearLayout 作为父级,我们将 android:layout_weight="1" 提供给 ExpandableListView 并且您的情况下 LinearLayout 是更好的解决方案。
    • 我了解您在LinearLayout 中所做的事情,但我只想知道使用RelativeLayout 有什么问题。特别是为什么底部栏也可以与ExpandableListView一起滚动。
    【解决方案2】:

    请将 android:layout_above="@+id/llbottom" 添加到您的可展开列表视图。并且不要将 android:layout_below="@+id/exSavedVoiceList" 添加到您的 llbottom 布局中。

    【讨论】:

    • 现在当我展开所有parent views 然后最后一个在llbottom
    猜你喜欢
    • 2012-10-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-03
    • 2016-06-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多