代码之家  ›  专栏  ›  技术社区  ›  putty174

更改可扩展列表方向

  •  0
  • putty174  · 技术社区  · 10 年前

    目前,我的可扩展列表从底部开始,所以看起来像这样:

    ------------------------------
    |                            |
    |                            |
    |                            |
    |                            |
    |^ Item 1                    |
    |    Item 1.1                |
    |    Item 1.2                |
    |    Item 1.3                |
    |v Item 2                    |
    |v Item 3                    |
    |v Item 4                    |
    ------------------------------
    

    有没有办法让它从顶部开始,而不是从底部开始?还是因为我选择了Holo Light主题?

    ------------------------------
    |^ Item 1                    |
    |    Item 1.1                |
    |    Item 1.2                |
    |    Item 1.3                |
    |v Item 2                    |
    |v Item 3                    |
    |v Item 4                    |
    |                            |
    |                            |
    |                            |
    -----------------------------
    

    主要片段:

    <RelativeLayout 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"
        android:paddingBottom="@dimen/activity_vertical_margin"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin"
        tools:context="com.wdi.wdigateway.CustomizeGatewayActivity$PlaceholderFragment" >
    
        <ExpandableListView
            android:id="@+id/components"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_above="@+id/done"
            android:layout_alignParentRight="true" >
    
        </ExpandableListView>
    </RelativeLayout>
    

    父视图:

    <?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:orientation="vertical" >
    
        <TextView
            android:id="@+id/parent"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:textSize="30sp"
            android:paddingTop="5sp"
            android:paddingBottom="5sp"
            android:paddingLeft="?android:attr/expandableListPreferredItemPaddingLeft" />
    
    </LinearLayout>
    

    子视图:

    <?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:orientation="vertical" >
    
        <TextView
            android:id="@+id/child"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:textSize="20sp"
            android:paddingTop="5sp"
            android:paddingBottom="5sp"
            android:paddingLeft="?android:attr/expandableListPreferredChildPaddingLeft" />
    
    </LinearLayout>
    
    1 回复  |  直到 10 年前
        1
  •  0
  •   Andrew T.    10 年前

    因为你把 android:layout_above="@+id/done" 而不指定顶部对齐。我想还有另一个视图叫做 done 在那里。

    要强制列表显示在顶部,还可以将 android:layout_alignParentTop="true" .

    <ExpandableListView
        android:id="@+id/components"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_above="@+id/done"
        android:layout_alignParentTop="true"
        android:layout_alignParentRight="true" >
    </ExpandableListView>