ScrollView中的片段高度不正确

时间:2013-08-26 16:38:51

标签: android android-fragments scrollview

尝试重现Roomorama的可用性页面,其中包含多个可滚动的Caldroid片段: https://www.dropbox.com/s/0kpb8435ffv1psp/Screenshot_2013-08-26-18-17-53.png

如果我将多个Caldroid片段添加到LinearLayout,那很好,完全没问题。但如果我将它嵌入ScrollView,高度将被搞砸,我会得到这个: https://www.dropbox.com/s/g3ntnkrnr8shbbv/Screenshot_2013-08-26-17-57-54.png

布局/ date_chooser.xaml

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/scroller"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:fillViewport="true" >

    <LinearLayout
        android:id="@+id/root"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >
    </LinearLayout>

</ScrollView>

的src /.../ DataChooser.java

...
protected void onCreate(Bundle arg0) {
    super.onCreate(arg0);
    setContentView(R.layout.date_chooser);

    ArrayList<CaldroidFragment> caldroidFragments = new ArrayList<CaldroidFragment>();
    for (int i = 0; i < 12; i++)
        caldroidFragments.add(buildCaldroidFragment());

    FragmentTransaction t = getSupportFragmentManager().beginTransaction();
    for (CaldroidFragment caldroidFragment2 : caldroidFragments)            
        t.add(R.id.root, caldroidFragment2);

    t.commit();
}
...

在这里您可以找到相关的代码段: https://gist.github.com/gabororosz/6343558

您有任何想法或解决方法吗?

谢谢!

1 个答案:

答案 0 :(得分:0)

片段中使用的布局应设置高度以包装内容。

相关问题