1.准备图片:
2.创建商品展示应用程序。先设计布局文件activity_main.xml代码:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_margin="8dp"
tools:context="cn.edu.bzu.showproduct.MainActivity">
<LinearLayout
android:id="@+id/addLL"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<EditText
android:id="@+id/nameET"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="商品名称"
android:inputType="textPersonName"/>
<EditText
android:id="@+id/balanceET"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="金额"
android:inputType="number"/>
<ImageView
android:onClick="add"
android:layout_width="30dp"
android:layout_height="32dp"
android:src="@drawable/input" />
</LinearLayout>
<ListView
android:id="@+id/accoutLV"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/addLL">
</ListView>
</LinearLayout>
使用ImageView的属性Android:src显示图片,只会显示图片原来的大小,不能修改。若用Android:background属性,就可以将使用的图片拉伸。
3.创建ListView布局需要建item.xml文件,代码:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="