如何使用在scrollview中使用多个列表视图

时间:2014-05-23 11:02:27

标签: android xml android-listview scrollview

基本上我正在为用户创建一个可以拥有他的教育和经验的个人资料。这些值可以是多个,所以我使用列表视图将它们包含在相对布局中,然后在滚动视图中。问题是当总大小增加时全屏大小滚动视图高度不会增加。

这是我的xml代码。并且对于列表视图的高度我正在增加它们各自的相对布局的高度,这是正常工作但问题是滚动视图

代码:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:fillViewport="false" >

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_margin="10dp"
    android:orientation="vertical" >

    <RelativeLayout
        android:id="@+id/profile_main_r"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/image_bg" >

        <ImageButton
            android:id="@+id/profile_list_button"
            android:layout_width="27dp"
            android:layout_height="15dp"
            android:layout_alignParentRight="true"
            android:layout_alignParentTop="true"
            android:layout_marginTop="6dp"
            android:background="@android:color/transparent"
            android:contentDescription="@string/profile_edit_buttons"
            android:src="@drawable/ic_edit"
            android:visibility="gone" />

        <ListView
            android:id="@+id/profile_list"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:cacheColorHint="@android:color/transparent"
            android:clickable="false"
            android:focusable="false"
            android:focusableInTouchMode="false"
            android:listSelector="@android:color/transparent"
            android:longClickable="false"
            android:orientation="horizontal" />
    </RelativeLayout>

    <RelativeLayout
        android:id="@+id/profile_experience_main"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/profile_main_r"
        android:layout_marginTop="8dp"
        android:background="@drawable/image_bg"
        android:cacheColorHint="@android:color/transparent"
        android:listSelector="@android:color/transparent"
        android:padding="6dp" >

        <ImageView
            android:id="@+id/profile_exp_icon"
            android:layout_width="30dp"
            android:layout_height="30dp"
            android:adjustViewBounds="true"
            android:contentDescription="@string/drawer_user_img"
            android:src="@drawable/ic_experience" />

        <TextView
            android:id="@+id/exp_text"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_toRightOf="@id/profile_exp_icon"
            android:padding="3dp"
            android:text="@string/experience"
            android:textColor="@color/dodger_blue"
            android:textSize="15sp"
            android:textStyle="normal"
            android:typeface="sans" />

        <ImageButton
            android:id="@+id/profile_experience_button"
            android:layout_width="30dp"
            android:layout_height="15dp"
            android:layout_alignParentRight="true"
            android:layout_alignParentTop="true"
            android:background="@android:color/transparent"
            android:contentDescription="@string/profile_edit_buttons"
            android:src="@drawable/ic_add"
            android:visibility="gone" />

        <ListView
            android:id="@+id/profile_experience_data"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_below="@id/profile_exp_icon"
            android:layout_marginTop="4dp"
            android:cacheColorHint="@android:color/transparent"
            android:clickable="false"
            android:divider="@android:color/transparent"
            android:dividerHeight="8dp"
            android:focusable="false"
            android:focusableInTouchMode="false"
            android:listSelector="@android:color/transparent"
            android:longClickable="false"
            android:padding="5dp" />
    </RelativeLayout>

    <RelativeLayout
        android:id="@+id/profile_education_main"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/profile_experience_main"
        android:layout_marginTop="8dp"
        android:background="@drawable/image_bg"
        android:cacheColorHint="@android:color/transparent"
        android:clickable="false"
        android:focusable="false"
        android:focusableInTouchMode="false"
        android:listSelector="@android:color/transparent"
        android:longClickable="false"
        android:padding="6dp" >

        <ImageView
            android:id="@+id/profile_edu_icon"
            android:layout_width="30dp"
            android:layout_height="30dp"
            android:adjustViewBounds="true"
            android:contentDescription="@string/drawer_user_img"
            android:src="@drawable/ic_education" />

        <TextView
            android:id="@+id/profile_education_text"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_toRightOf="@id/profile_edu_icon"
            android:padding="4dp"
            android:text="@string/education"
            android:textColor="@color/dodger_blue"
            android:textSize="15sp"
            android:textStyle="normal"
            android:typeface="sans" />

        <ImageButton
            android:id="@+id/profile_education_button"
            android:layout_width="30dp"
            android:layout_height="15dp"
            android:layout_alignParentRight="true"
            android:layout_alignParentTop="true"
            android:background="@android:color/transparent"
            android:contentDescription="@string/profile_edit_buttons"
            android:src="@drawable/ic_add"
            android:visibility="gone" />

        <ListView
            android:id="@+id/profile_education_data"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_below="@id/profile_edu_icon"
            android:layout_marginTop="2dp"
            android:cacheColorHint="@android:color/transparent"
            android:clickable="false"
            android:divider="@android:color/transparent"
            android:dividerHeight="8dp"
            android:focusable="false"
            android:focusableInTouchMode="false"
            android:listSelector="@android:color/transparent"
            android:longClickable="false"
            android:padding="5dp"
            android:paddingLeft="2dp" />
    </RelativeLayout>

    <Button
        android:id="@+id/project_button"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/profile_education_main"
        android:layout_marginTop="5dp"
        android:background="@drawable/button_design"
        android:text="@string/view_projects"
        android:textColor="@color/white" />

</RelativeLayout>

1 个答案:

答案 0 :(得分:1)

您无法在滚动视图中使用ListView,因为listview已包含滚动视图。