我已经尝试将ListVIEw放在linearLayout中并为其分配权重.尝试了relativeLayout.此外,我已经构建了ListVIEw programmaticaly,而不使用xml布局.甚至在将视图添加到VIEwGroup之前更改了LayoutParams.
我也考虑过这些帖子:Width of clickable area in ListView w/ onListItemClick,In Android,how can I set a ListView item’s height and width?,Android Listview width prob.
任何想法为什么项目不扩展到填充宽度?以及如何扩展它们?
MyVIEwGroup类:
public class MyVIEwGroup extends VIEwGroup { public MyVIEwGroup(Context context,AttributeSet attrs) { super(context,attrs); generateMyVIEwGroup(); } private voID generateMyVIEwGroup() { ListVIEw main = (ListVIEw) VIEw.inflate(getContext(),R.layout.layout_main,null); main.setAdapter(new MyAdapter(getContext())); this.addVIEw(main); } @OverrIDe protected voID onLayout(boolean changed,int l,int t,int r,int b) { this.getChildAt(0).layout(l,t,r,b); }}
ListVIEw xml布局:
<?xml version="1.0" enCoding="utf-8"?><ListVIEw xmlns:androID="http://schemas.androID.com/apk/res/androID" androID:ID="@androID:ID/List" androID:layout_wIDth="fill_parent" androID:layout_height="wrap_content" androID:layout_marginRight="3dp" androID:background="#77000000" androID:cachecolorHint="#00000000" androID:divIDer="#00000000" androID:divIDerHeight="0dp" androID:drawSelectorOntop="false" androID:scrollbars="vertical" ></ListVIEw>
ListVIEw项目布局:
<?xml version="1.0" enCoding="utf-8"?><linearLayout xmlns:androID="http://schemas.androID.com/apk/res/androID" androID:ID="@+ID/layout_main_category" androID:layout_wIDth="fill_parent" androID:layout_height="wrap_content" androID:background="@color/mainBackground" androID:gravity="fill_horizontal|center_vertical" androID:orIEntation="vertical" > <TextVIEw androID:ID="@+ID/main_category" androID:layout_wIDth="fill_parent" androID:layout_height="wrap_content" androID:layout_marginleft="8dp" androID:layout_marginRight="8dp" androID:paddingBottom="7dp" androID:paddingleft="20dp" androID:paddingRight="5dp" androID:paddingtop="20dp" androID:text="test" androID:textcolor="@color/maincategory" androID:textSize="15sp" androID:textStyle="bold" /></linearLayout>
MyAddapter类的一部分:
public VIEw getVIEw(int position,VIEw convertVIEw,VIEwGroup parent) { VIEwHolder vIEwHolder; if(null == convertVIEw) { LayoutInflater inflater = LayoutInflater.from(context); convertVIEw = inflater.inflate(R.layout.layout_main_category,null); vIEwHolder = new VIEwHolder(); vIEwHolder.mainItemTitle = (TextVIEw) convertVIEw.findVIEwByID(R.ID.main_category); convertVIEw.setTag(vIEwHolder); } else { vIEwHolder = (VIEwHolder) convertVIEw.getTag(); } vIEwHolder.mainItemTitle.setText("text"); return convertVIEw;}private static class VIEwHolder { public TextVIEw menuItemTitle;}解决方法 VIEwGroup最终没有正常工作.我也试过使用linearLayout.但是relativeLayout最终正确地夸大了布局.所以,我的xml布局和适配器保持不变,但我更改了主类以扩展relativeLayout.还删除了onLayout().
MyVIEw类:
public class MyVIEw extends relativeLayout { //Extra code unchanged .... private voID generateMyVIEw() { ListVIEw menu = (ListVIEw) VIEw.inflate(getContext(),null); menu.setAdapter(new MyAdapter(getContext())); this.addVIEw(menu); } //Removed onLayout()}总结
以上是内存溢出为你收集整理的android – ListView项不会将width扩展到fill_parent全部内容,希望文章能够帮你解决android – ListView项不会将width扩展到fill_parent所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)