linearLayout ScrollVIEw relativeLayout linearLayout <ListVIEw androID:ID="@androID:ID/List" androID:layout_wIDth="match_parent" androID:layout_height="fill_parent" androID:layout_margin="5dip" androID:layout_weight="30" > </ListVIEw> linearLayout
这是我的BaseAdapter类
public class APIQuickCheckoutProductProvIDer extends BaseAdapter {private Activity activity;private ArrayList<HashMap<String,String>> data;private static LayoutInflater inflater = null;public APIQuickCheckoutProductProvIDer(Activity a,ArrayList<HashMap<String,String>> d) { activity = a; data = d; inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);}public int getCount() { return data.size();}public Object getItem(int position) { return position;}public long getItemID(int position) { return position;}@OverrIDepublic VIEw getVIEw(int position,VIEw convertVIEw,VIEwGroup parent) { VIEw vi = convertVIEw; if (convertVIEw == null) vi = inflater.inflate(R.layout.product_item,null); TextVIEw brand = (TextVIEw) vi.findVIEwByID(R.ID.brands); TextVIEw quantity_name = (TextVIEw) vi.findVIEwByID(R.ID.quantity_name); TextVIEw price = (TextVIEw) vi.findVIEwByID(R.ID.price); HashMap<String,String> product = new HashMap<String,String>(); product = data.get(position); // Setting all values in ListvIEw brand.setText(product.get(APIQuickCheckout.KEY_BRAND)); quantity_name.setText(product.get(APIQuickCheckout.KEY_QUANTITY_name)); price.setText(product.get(APIQuickCheckout.KEY_PRICE)); return vi;}}
这是我设置适配器的主要类:
adapter = new APIQuickCheckoutProductProvIDer(APIQuickCheckout.this,productList);lv.setAdapter(adapter);adapter.notifyDataSetChanged();
最后,这是我设置到列表视图的每一行
<?xml version="1.0" enCoding="utf-8"?>
<linearLayout xmlns:androID="http://schemas.androID.com/apk/res/androID" androID:layout_wIDth="0dip" androID:layout_height="wrap_content" androID:orIEntation="vertical" androID:padding="5dip" androID:layout_weight="7" androID:weightSum="6" > <TextVIEw androID:ID="@+ID/brands" androID:layout_wIDth="wrap_content" androID:layout_height="0dp" androID:layout_weight="3" /> <TextVIEw androID:ID="@+ID/quantity_name" androID:layout_wIDth="wrap_content" androID:layout_height="0dp" androID:layout_weight="3" /> </linearLayout> <linearLayout androID:layout_wIDth="0dip" androID:layout_height="wrap_content" androID:layout_weight="1" /><linearLayout xmlns:androID="http://schemas.androID.com/apk/res/androID" androID:layout_wIDth="0dip" androID:layout_height="wrap_content" androID:orIEntation="vertical" androID:padding="5dip" androID:layout_weight="2" androID:weightSum="6" > <TextVIEw androID:layout_wIDth="wrap_content" androID:layout_height="0dip" androID:layout_weight="3" /> <TextVIEw androID:ID="@+ID/price" androID:layout_wIDth="wrap_content" androID:layout_height="0dip" androID:layout_weight="3" /> </linearLayout> </linearLayout>
但是,当我尝试上面提到的代码时,它会显示第一个产品,而我只能看到第二个产品的顶部.从那时起我就什么都看不见了.那么,当我添加新产品时,如何动态更改ListVIEw的高度?为了显示所有这些.
解决方法 如果要动态更改列表视图的高度,可以使用,List.setLayoutParams(new linearLayout.LayoutParams(LayoutParams.FILL_PARENT,theSizeIWant));总结
以上是内存溢出为你收集整理的更改Listview dynamicAndroid的高度全部内容,希望文章能够帮你解决更改Listview dynamicAndroid的高度所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)