【发布时间】:2015-05-19 13:08:40
【问题描述】:
我想滚动屏幕中的一部分数据,为此我在布局中添加了滚动视图,但列表视图没有滚动,它在模拟器中工作正常。我阅读了所有相关的文章,其中说 listview 滚动是不可能的,并尝试了设计自定义滚动的替代方法,但只有部分数据没有滚动。为什么会这样?没有其他选择?
我的布局是这样的
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
//few more layout items goes here
<LinearLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ListView android:id="@+id/listView"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:divider="#00000000"
android:dividerHeight="5dp"
android:textStyle="bold"
android:typeface="serif"
/>
<LinearLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Total"
android:textStyle="bold"
android:textColor="#F5D8BA"
android:layout_marginRight="30dp"
android:layout_gravity="center"
android:typeface="serif"
/>
</LinearLayout>
</LinearLayout>
</ScrollView>
listview里面的数据是这样的
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/scrollView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:layout_weight="1"
>
<LinearLayout
android:layout_width="75dp"
android:layout_height="wrap_content" android:orientation="vertical">
<TextView
android:id="@+id/textView1"
android:layout_gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="12dp"
android:textColor="#000000"
android:text="TextView"
android:textStyle="bold"
android:typeface="serif"
/>
<TextView
android:id="@+id/textViewStyle"
android:layout_gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="12dp"
android:textColor="#000000"
android:textStyle="bold"
android:typeface="serif"
/>
</LinearLayout>
</LinearLayout>
</ScrollView>
【问题讨论】:
-
从列表视图数据中移除滚动视图...
-
您在使用 ListView 时不需要 ScrollView .. 进一步您可以向 ListView 添加页眉或页脚视图
-
是的,它现在可以工作了,但是我在列表视图下面的元素很少,它不在视图中,我的意思是推到屏幕内,所以我添加了滚动视图,我将如何处理?我有几个按钮和其他部分。
标签: android android-layout scroll android-scrollview