This question already has an answer here:
这个问题在这里已有答案:
- Android list view inside a scroll view 29 answers
- 滚动视图里面的Android列表视图29答案
This is the first part of my xml : https://ibb.co/fkEAAv
这是我的xml的第一部分:https://ibb.co/fkEAAv
Then this one is the second part of the xml: https://ibb.co/hMZGiF
然后这个是xml的第二部分:https://ibb.co/hMZGiF
My problem is:
我的问题是:
- I can't populate my list view properly, there's actually 5 comments should be display but it only shows 2 comments.
- 我无法正确填充列表视图,实际上应该显示5条评论,但它只显示2条评论。
- I can't scroll my listview.
- 我不能滚动我的列表视图。
Here is the xml code:
这是xml代码:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/ScrollView01"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:scrollbars="none" >
<LinearLayout
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="600dp"
android:background="@drawable/taskdetails"
>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Proceed"
android:background="#84B281"
android:id="@+id/button15"
android:layout_alignParentBottom="true"
android:layout_marginBottom="20dp"
android:layout_marginRight="10dp"
android:layout_marginLeft="10dp"
android:layout_alignEnd="@+id/editText24"
android:layout_alignStart="@+id/editText24" />
<EditText
android:layout_width="400dp"
android:layout_height="150dp"
android:id="@+id/editText21"
android:theme="@style/wat"
android:hint="Description"
android:inputType="textMultiLine"
android:lines="8"
android:textColor="#994495"
android:minLines="6"
android:gravity="top|left"
android:maxLines="10"
android:enabled="true"
android:focusableInTouchMode="false"
android:scrollbars="vertical"
android:layout_alignParentStart="false"
android:layout_marginTop="120dp"
android:layout_marginBottom="15dp"
android:layout_alignParentEnd="false"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/editText22"
android:theme="@style/wat"
android:gravity="center"
android:textColor="#994495"
android:backgroundTint="#994495"
android:enabled="true"
android:focusableInTouchMode="false"
android:scrollbars="vertical"
android:hint="When will it start?"
android:layout_below="@+id/editText21"
android:layout_alignParentStart="false"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="15dp" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/editText23"
android:theme="@style/wat"
android:gravity="center"
android:backgroundTint="#994495"
android:enabled="true"
android:focusableInTouchMode="false"
android:scrollbars="vertical"
android:hint="When will it end?"
android:layout_below="@+id/editText22"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="20dp" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/editText24"
android:theme="@style/wat"
android:backgroundTint="#994495"
android:enabled="true"
android:focusableInTouchMode="false"
android:scrollbars="vertical"
android:hint="Any specific time?"
android:layout_below="@+id/editText23"
android:layout_alignParentStart="false"
android:layout_marginLeft="10dp"
android:gravity="center"
android:layout_marginRight="10dp"
android:layout_marginTop="20dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Task Schedule:"
android:textSize="18dp"
android:textColor="#994495"
android:id="@+id/textView22"
android:layout_centerHorizontal="true"
android:layout_marginTop="280dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="26sp"
android:text="Title"
android:id="@+id/textView23"
android:textColor="#090"
android:layout_marginTop="85dp"
android:layout_marginLeft="100dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Text"
android:id="@+id/emails"
android:visibility="invisible"
android:layout_alignParentTop="true"
android:layout_toEndOf="@+id/textView22" />
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_weight="0"
android:layout_height="50dp"
android:background="@drawable/comments"
android:layout_marginBottom="0dp">
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="200dp" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageView3" />
<ListView
android:id="@+id/listView"
android:background="#fff"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
</LinearLayout>
</ScrollView>
3 个解决方案
#1
0
You can use NestedScrollView instead of ScrollView. and please replace Listview with RecyclerView.
您可以使用NestedScrollView而不是ScrollView。请将Listview替换为RecyclerView。
you can find example from here
你可以从这里找到例子
NestedScrollView is just like ScrollView, but it supports acting as both a nested scrolling parent and child on both new and old versions of Android. Nested scrolling is enabled by default.
NestedScrollView就像ScrollView一样,但它支持在新旧版本的Android上充当嵌套滚动父级和子级。默认情况下启用嵌套滚动。
#2
0
In your LinearLayout, child of the ScrollView, change android:layout_height="match_parent" to android:layout_height="wrap_content".
在您的LinearLayout,ScrollView的子项中,将android:layout_height =“match_parent”更改为android:layout_height =“wrap_content”。
That will makes this container being greater than a screen.
这将使该容器大于屏幕。
Then, unfortunately, having a vertical sliding component in a ScrollView is never a good idea. If the ListView is not populated by changing the layout_height, try to add the comments manually like findviewbyid(R.id.xxx).addView(adapter.getView(...)). Of course, it is not the real code, but that's the idea.
然而,遗憾的是,在ScrollView中使用垂直滑动组件绝不是一个好主意。如果未通过更改layout_height来填充ListView,请尝试手动添加注释,如findviewbyid(R.id.xxx).addView(adapter.getView(...))。当然,这不是真正的代码,但这就是主意。
#3
-1
Put Only one attribute on scroll view.
在滚动视图上只放置一个属性。
Like Only one Linear Layout in Scroll view and All other Attribute on Linear Layout.
类似于滚动视图中的一个线性布局和线性布局上的所有其他属性。
#1
0
You can use NestedScrollView instead of ScrollView. and please replace Listview with RecyclerView.
您可以使用NestedScrollView而不是ScrollView。请将Listview替换为RecyclerView。
you can find example from here
你可以从这里找到例子
NestedScrollView is just like ScrollView, but it supports acting as both a nested scrolling parent and child on both new and old versions of Android. Nested scrolling is enabled by default.
NestedScrollView就像ScrollView一样,但它支持在新旧版本的Android上充当嵌套滚动父级和子级。默认情况下启用嵌套滚动。
#2
0
In your LinearLayout, child of the ScrollView, change android:layout_height="match_parent" to android:layout_height="wrap_content".
在您的LinearLayout,ScrollView的子项中,将android:layout_height =“match_parent”更改为android:layout_height =“wrap_content”。
That will makes this container being greater than a screen.
这将使该容器大于屏幕。
Then, unfortunately, having a vertical sliding component in a ScrollView is never a good idea. If the ListView is not populated by changing the layout_height, try to add the comments manually like findviewbyid(R.id.xxx).addView(adapter.getView(...)). Of course, it is not the real code, but that's the idea.
然而,遗憾的是,在ScrollView中使用垂直滑动组件绝不是一个好主意。如果未通过更改layout_height来填充ListView,请尝试手动添加注释,如findviewbyid(R.id.xxx).addView(adapter.getView(...))。当然,这不是真正的代码,但这就是主意。
#3
-1
Put Only one attribute on scroll view.
在滚动视图上只放置一个属性。
Like Only one Linear Layout in Scroll view and All other Attribute on Linear Layout.
类似于滚动视图中的一个线性布局和线性布局上的所有其他属性。