我有一个带有相关 activity.xml 代码的活动:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/pattern_background"
android:orientation="vertical" >
<ScrollView
android:id="@+id/scrollView"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginBottom="5dp"
android:layout_weight="1"
android:clickable="false" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
...
<LinearLayout
android:id="@+id/llComments"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:orientation="vertical" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
</LinearLayout>
</ScrollView>
<include
android:id="@+id/layoutComments"
android:layout_width="match_parent"
android:layout_height="wrap_content"
layout="@layout/widget_comentarios_fragment" >
</include>
在 ID 为 llComments 的 LinearLayout 中,我使用以下代码从活动中动态引入了一个名为 CommentsFragment 的片段:
private Fragment commentsFragment;
private FragmentTransaction ft;
...
llComentarios = (LinearLayout) findViewById(R.id.llComments);
...
Bundle args = new Bundle();
args.putString(Constants.IDMODEL, getId());
commentsFragment = CommentsFragment.newInstance(args);
ft = getSupportFragmentManager().beginTransaction();
ft.add(R.id.llComments, commentsFragment).commit();
Fragment 关联的 xml 文件为:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ListView
android:id="@+id/comments"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:divider="@color/transparent"
android:dividerHeight="10dp"
android:paddingLeft="@dimen/indicator_internal_padding"
android:paddingRight="@dimen/indicator_internal_padding" />
</LinearLayout>
如果我不固定列表视图的高度,我无法解决的问题是在活动中显示列表中的多个项目(实际上我正在显示一个和第三个项目)。它应该适应我添加的尽可能多的项目通过适配器到片段中的列表。我在布局和视图中尝试了不同的高度组合,但仍然不起作用。也许我正在与其他人取消一个。
任何帮助,将不胜感激。
提前致谢