【问题标题】:how to use use more than one list views in scrollview如何在滚动视图中使用多个列表视图
【发布时间】:2014-05-23 11:02:27
【问题描述】:

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

这是我的 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>

【问题讨论】:

  • 为什么没有展开式列表?
  • 您可以将另一个ListView 移动到另一个Tab 中,或者按照@Saqib 的建议进行操作。

标签: android xml android-listview scrollview


【解决方案1】:

你不能在滚动视图中使用 ListView,因为 listview 已经包含一个滚动视图。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-21
    • 1970-01-01
    相关资源
    最近更新 更多