带有两个列表片段的可滚动布局
Posted
技术标签:
【中文标题】带有两个列表片段的可滚动布局【英文标题】:Scrollable layout with two listfragments 【发布时间】:2012-10-25 00:57:57 【问题描述】:我创建了一个带有两个列表片段的滚动视图,代码如下:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_
android:layout_
android:background="@drawable/blue_shade_top_gainers_and_loosers"
android:orientation="vertical" >
<LinearLayout
android:layout_
android:layout_
android:paddingBottom="1dip"
android:paddingLeft="1dip"
android:paddingRight="1dip"
android:paddingTop="2dip" >
<fragment
android:id="@+id/header_fragment"
android:name="com.lk.ignitionit.cse.util.HeaderFragmentActivity"
android:layout_
android:layout_ />
</LinearLayout>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/ScrollView13"
android:layout_
android:layout_ >
<RelativeLayout
android:id="@+id/rl_top"
android:layout_
android:layout_
android:layout_marginBottom="1dip"
android:layout_marginLeft="1dip"
android:layout_marginRight="1dip"
android:layout_marginTop="1dip"
>
<LinearLayout
android:id="@+id/headg"
android:layout_
android:layout_
android:scrollbars="vertical" >
<include layout="@layout/top_gainer_header" />
</LinearLayout>
<fragment
android:id="@+id/gain"
android:name="com.lk.ignitionit.cse.application.TopGainersFragmentActivity"
android:layout_
**android:layout_**
android:layout_below="@+id/headg" />
<LinearLayout
android:id="@+id/headl"
android:layout_
android:layout_
android:layout_below="@+id/gain" >
<include layout="@layout/top_loosers_header" />
</LinearLayout>
<fragment
android:name="com.lk.ignitionit.cse.application.TopLoosersFragmantActivity"
android:layout_
**android:layout_**
android:layout_below="@+id/headl" />
</RelativeLayout>
</ScrollView>
</LinearLayout>
但输出没有显示整个列表
然后我将片段布局高度更改为 240dip 而不是“wrap_content”,现在它足以显示整个列表。 但问题是,这些数据是动态的,每个列表片段都有 10 个列表项。所以我无法预测片段的高度。如果名字很长,这个高度是不够的。
所以我需要将片段高度设置为 wrap_content 并可以滚动。我该怎么做?
【问题讨论】:
【参考方案1】:已经有几个关于这个的问题。似乎没有完美的答案,但有几个指针。请搜索它们。一个例子:
Scrolling with multiple listviews for android
【讨论】:
我可以使用固定高度来解决这个问题。但是在不同的屏幕上会发生什么。这是最佳做法吗? 有很多选项,例如使用和可扩展列表,转换为具有不同标题的列表等。使用最适合您需要的...以上是关于带有两个列表片段的可滚动布局的主要内容,如果未能解决你的问题,请参考以下文章