目前,我有如下的布局我如何能自动调整大小列表视图,因此不会滚动
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_marginTop="9px"
android:layout_below="@+id/desc"
android:id="@+id/ll_item"
android:orientation="vertical"
android:paddingRight="3px"
android:paddingLeft="3px"
android:paddingBottom="5px"
android:paddingTop="5px"
android:background="@drawable/rounded_corner_lists" >
<!--
<ListView android:drawSelectorOnTop="false" android:id="@+id/lv" android:layout_height="fill_parent" android:layout_width="wrap_content" android:divider="#ddd" android:dividerHeight="1px" android:background="@drawable/white" />
-->
</LinearLayout>
,我已经注释掉列表视图,我试图让这个在XML中,以高度设定到WRAP_CONTENT,FILL_PARENT,目前我与编程下面的代码
LinearLayout ll_item = (LinearLayout) this.findViewById(R.id.ll_item);
if(list.length() > 0)
{
ll_item.setVisibility(View.VISIBLE);
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,calcListHeight(list));
listview = new ListView(this);
listview.setBackgroundResource(R.drawable.white);
listview.setDivider(new ColorDrawable(this.getResources().getColor(R.drawable.dividercolor)));
listview.setDividerHeight(1);
listview.setCacheColorHint(0);
mAdapter = new JSONAdapter(list, this);
listview.setAdapter(mAdapter);
mAdapter.notifyDataSetChanged();
ll_item.addView(listview, lp);
}
这这样做是结果
这样你就可以在这个图像中看到的,因为我包含在LinearLayout中的列表视图,以获得圆角的外观,它不只是自动延伸到包含整个列表视图,没有任何如何让这两个元素垂直包装内容,以便在没有编程设置高度的情况下不会滚动? ? ?
我想一两件事,我应该提到的是,我拥有这一切的布局在滚动视图,因为我想这个列表视图是整个布局的一个微小的款,所以它会像
-scrollview
-textview
-textview
-linearlayout
-listview
- 按钮
这里是我有什么
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:orientation="vertical" android:layout_height="fill_parent" android:layout_width="fill_parent"
android:background="@drawable/bg" xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/titlebar">
<ScrollView android:id="@+id/sv" android:layout_width="fill_parent" android:background="@drawable/bg"
android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android">
<RelativeLayout android:id="@+id/widget28"
android:layout_width="fill_parent" android:layout_height="fill_parent" android:padding="4dip"
>
<LinearLayout android:orientation="vertical" style="@style/rounded_corner_full_width_button"
android:id="@+id/editfields">
<ListView android:drawSelectorOnTop="false" android:id="@+id/lv" android:layout_height="fill_parent"
android:layout_width="wrap_content" android:divider="#ddd" android:dividerHeight="1px"
android:background="@drawable/white"/>
</LinearLayout>
</RelativeLayout>
</ScrollView>
</LinearLayout>
感谢亚当,我已经有一个适配器,我能够与使用的LinearLayout您提示重新使用。 – 2011-06-01 22:26:31
谢谢!与Artem相同,我可以使用线性布局重新使用我的适配器。 – hyui 2011-11-07 15:45:23
谢谢亚当。你的适配器是否需要异步?当我尝试这个时,它只抓住我的第一个项目,就像适配器没有完成加载。 – annie 2012-09-10 18:11:45