
所以,我的项目布局(thread_item.xml)如下所示:
<?xml version="1.0" enCoding="utf-8"?><relativeLayout xmlns:androID="http://schemas.androID.com/apk/res/androID" androID:layout_wIDth="fill_parent" androID:layout_height="300dip" > <TextVIEw androID:ID="@+ID/thread_item_Title" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:text="[dummy]" androID:textSize="20dip" androID:textStyle="bold" /> <ImageVIEw androID:ID="@+ID/thread_first_image" androID:layout_below="@ID/thread_item_Title" androID:scaleType="centerInsIDe" androID:maxWIDth="100dip" androID:maxHeight="100dip" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:adjustVIEwBounds="true" /> <TextVIEw androID:ID="@+ID/thread_item_prevIEw" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:layout_aligntop="@ID/thread_first_image" androID:text="[dummy]" androID:textSize="15dip"> </TextVIEw></relativeLayout>
我将根元素的layout_height设置为300dip,并且希望所有项目具有相同的高度,但是它们没有.当我运行应用程序时,它的高度看起来像一个wrap_content值.
此外,活动本身如下所示:
public class ThreadListActivity extends ListActivity { public voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); /* Code to get items from the storage. */ setlistadapter(new ThreadItemAdapter(this,R.layout.thread_item,itemsArray))); getListVIEw().setonItemClickListener(new AdapterVIEw.OnItemClickListener() { @OverrIDe public voID onItemClick(AdapterVIEw<?> adapterVIEw,VIEw vIEw,int position,long ID) { /*Start new Activity. Unrelated stuff.*/ } }); }} 而我正在使用的适配器如下所示:
public class ThreadItemAdapter extends ArrayAdapter<ThreadItem> { Activity context; List<ThreadItem> items; public ThreadItemAdapter(Activity context,int textVIEwResourceID,List<ThreadItem> items) { super(context,textVIEwResourceID,items); this.context = context; this.items = items; } @OverrIDe public VIEw getVIEw(int position,VIEw convertVIEw,VIEwGroup parent) { LayoutInflater inf = this.context.getLayoutInflater(); VIEw result; if (convertVIEw == null) { result = inf.inflate(R.layout.thread_item,null); } else { result = convertVIEw; } TextVIEw tbTitle = (TextVIEw) result.findVIEwByID(R.ID.thread_item_Title); TextVIEw tbPrevIEw = (TextVIEw) result.findVIEwByID(R.ID.thread_item_prevIEw); ImageVIEw ivFirstimage = (ImageVIEw) result.findVIEwByID(R.ID.thread_first_image); ThreadItem item = items.get(position); tbTitle.setText(item.getThreadTitle()); ivFirstimage.setimageBitmap(item.getFirstimage()); SimpleLeadingmarginSpan span = new SimpleLeadingmarginSpan(item.getFirstimage() != null ? 5 : 0,115); // Todo: const SpannableString prevIEwText = new SpannableString(item.getThreadPrevIEw()); prevIEwText.setSpan(span,prevIEwText.length(),0); tbPrevIEw.setText(prevIEwText); return result; }} 我看不清为什么所有的列表项仍然包装他们的内容,不要保持300dip的高度.它们可能小于或者大于300dip.
我正在使用AndroID 2.3.3,测试HTC Evo 3D设备和仿真器(都显示相同的结果).
非常感谢!
UPD:
感谢米格尔和萨姆.解决方案是将maxHeight设置为textVIEw,这使我的列表项目增长(这将是ID / thread_item_prevIEw),并将relativeLayout的minHeight设置为300dip,以防止它收缩.
解决方法 如果您将行中的所有子视图高度从wrap_content更改为match_parent会怎么样?从评论
你尝试过minHeight和maxHeight属性吗?例如:
androID:minHeight="300dp"
你也应该看看AndroID的Romain Guy discuss efficiency in adapters and getView().
以上是内存溢出为你收集整理的Android ListView固定高度项全部内容,希望文章能够帮你解决Android ListView固定高度项所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)