<?xml version="1.0" enCoding="utf-8"?><relativeLayout xmlns:androID="http://schemas.androID.com/apk/res/androID" androID:layout_wIDth="match_parent" androID:layout_height="match_parent" androID:padding="16dp"> <ImageVIEw androID:ID="@+ID/iv" androID:layout_wIDth="120dp" androID:layout_height="90dp" androID:layout_centerVertical="true"/> <relativeLayout androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:layout_marginleft="10dp" androID:layout_toRightOf="@+ID/iv" androID:layout_centerVertical="true"> <TextVIEw androID:ID="@+ID/Title" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:text="桌子" androID:textSize="20sp" androID:textcolor="#000000"/> <TextVIEw androID:ID="@+ID/tv_price" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:text="价格" androID:textSize="20sp" androID:layout_margintop="10dp" androID:layout_below="@+ID/Title" androID:textcolor="#FF8F03"/> <TextVIEw androID:ID="@+ID/price" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:text="1000" androID:textSize="20sp" androID:layout_below="@+ID/Title" androID:layout_toRightOf="@ID/tv_price" androID:textcolor="#FF8F03" androID:layout_margintop="10dp"/> </relativeLayout></relativeLayout>
<?xml version="1.0" enCoding="utf-8"?><relativeLayout xmlns:androID="http://schemas.androID.com/apk/res/androID" xmlns:app="http://schemas.androID.com/apk/res-auto" xmlns:tools="http://schemas.androID.com/tools" androID:layout_wIDth="match_parent" androID:layout_height="match_parent" androID:paddingBottom="@dimen/activity_vertical_margin" androID:paddingleft="@dimen/activity_horizontal_margin" androID:paddingRight="@dimen/activity_horizontal_margin" androID:paddingtop="@dimen/activity_vertical_margin" tools:context=".MainActivity" > <TextVIEw androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:text="购物商城" androID:textSize="18sp" androID:textcolor="#FFFFFF" androID:background="#FF8F03" androID:gravity="center"/> <ListVIEw androID:ID="@+ID/lv" androID:layout_wIDth="match_parent" androID:layout_height="wrap_content"/></relativeLayout>
package com.example.ListvIEw;import androID.app.AliasActivity;import androID.os.Bundle;import androID.vIEw.VIEw;import androID.vIEw.VIEwGroup;import androID.Widget.BaseAdapter;import androID.Widget.ImageVIEw;import androID.Widget.ListVIEw;import androID.Widget.TextVIEw;public class MainActivity extends AliasActivity { private ListVIEw mListvIEw; private String[] Titles = {"桌子", "苹果", "蛋糕", "秋衣", "猕猴桃", "围巾"}; private String[] prices = {"180元", "10元/kg", "188元", "99元", "10元/kg", "199元"}; private int[] icons = {R.drawable.table, R.drawable.apple, R.drawable.cake, R.drawable.wireclothes, R.drawable.kiwiftuit, R.drawable.scarf}; @OverrIDe protected voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentVIEw(R.layout.activity_main); mListvIEw = (ListVIEw) findVIEwByID(R.ID.iv); MyBaseAdapter mAdapter = new MyBaseAdapter(); mListvIEw.setAdapter(mAdapter); } class VIEwHolder { TextVIEw Title, price; ImageVIEw iv; } class MyBaseAdapter extends BaseAdapter { @OverrIDe public int getCount() { return Titles.length; } @OverrIDe public Object getItem(int position) { return Titles[position]; } @OverrIDe public long getItemID(int position) { return position; } @OverrIDe public VIEw getVIEw(int position, VIEw convertVIEw, VIEwGroup parent) { VIEwHolder holder = null; if (convertVIEw == null) { convertVIEw = VIEw.inflate(MainActivity.this, R.layout.activity_main, null); holder = new VIEwHolder(); holder.Title = (TextVIEw) convertVIEw.findVIEwByID(R.ID.Title); holder.price = (TextVIEw) convertVIEw.findVIEwByID(R.ID.price); holder.iv = (ImageVIEw) convertVIEw.findVIEwByID(R.ID.iv); convertVIEw.setTag(holder); } else { holder = (VIEwHolder) convertVIEw.getTag(); } holder.Title.setText(Titles[position]); holder.price.setText(prices[position]); holder.iv.setBackgroundResource(icons[position]); return convertVIEw; } }}
总结
以上是内存溢出为你收集整理的购物商城全部内容,希望文章能够帮你解决购物商城所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)