java 使android listview布局可滚动
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4310738/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Making android listview layout scrollable
提问by David C
I have an xml file that has the layout in ASCII form:
我有一个 xml 文件,其布局为 ASCII 格式:
---------------
| ImageView
--------------
| TextView
--------------
| List...
--------------
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:myapp="http://schemas.android.com/apk/res/com.some.app"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView
android:id="@+id/MovieCover"
android:layout_width="100dip"
android:layout_height="100dip"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="16sp"
android:padding="10dp"
android:id="@+id/TextHeader"
android:background="#000000">
</TextView>
<ListView android:id="@+id/ListView02" android:layout_height="wrap_content"
android:layout_width="fill_parent">
</ListView>
</LinearLayout>
I'm having a problem displaying the layout when my ImageView and TextView takes up more than 3/4 of the screen. How do I make ImageView and TextView scrollable with the ListView that is being displayed? At this point of time, only the ListView to be scrolled and I want the entire layout to be scrollable as though they are one page on its own.
当我的 ImageView 和 TextView 占据屏幕的 3/4 以上时,我在显示布局时遇到问题。如何使用正在显示的 ListView 使 ImageView 和 TextView 可滚动?此时,只有 ListView 要滚动,我希望整个布局都可以滚动,就像它们自己是一页一样。
How can I do that?
我怎样才能做到这一点?
采纳答案by Andreas Wong
You can use <ScrollView>
as your layout container
您可以<ScrollView>
用作布局容器
something along the line of
沿线的东西
<ScrollView>
<LinearLayout>
// your layout here
</LinearLayout>
</ScrollView>
the reason why we need the LinearLayout inside is that ScrollView can only have one direct child
我们需要里面的 LinearLayout 的原因是 ScrollView 只能有一个直接的孩子
回答by Labeeb Panampullan
Butter to use two LinearLayout with layoutweight="1"
and put ScrollView in one and listview in other
黄油使用两个 LinearLayoutlayoutweight="1"
并将 ScrollView 放在一个中,将列表视图放在另一个中
<LinearLayout android:layout_weight="1"
android:layout_height="fill_parent" android:layout_width="fill_parent">
<ScrollView android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<!-- scroll view content -->
</LinearLayout>
</ScrollView>
</LinearLayout>
<LinearLayout android:layout_weight="1"
android:layout_height="fill_parent" android:layout_width="fill_parent">
<ListView android:id="@+id/ListView02" android:layout_height="wrap_content"
android:layout_width="fill_parent">
</ListView>
</LinearLayout>
回答by Arun
ListView has addtoHeader and addtoFooter function. Make a separate layout and add it into header of ListView . In your case make a relative layout of imageview and textview and add it to the header of listview. The entire page will start scrolling.
ListView 具有 addtoHeader 和 addtoFooter 功能。制作一个单独的布局并将其添加到 ListView 的标题中。在您的情况下,制作 imageview 和 textview 的相对布局并将其添加到列表视图的标题中。整个页面将开始滚动。
回答by Suresh
How about putting the ImageView and TextView in a layout and putting this layout inside a ScrollView.?
把 ImageView 和 TextView 放在一个布局中,然后把这个布局放在一个 ScrollView 中怎么样?