package com.example.iop;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
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 ActionBarActivity {
private String[] t = { "京东商城", "QQ", "QQ斗地主", "新浪微博", "天猫", "UC游览器","微信"};
private int[] i = { R.drawable.jd, R.drawable.qq,
R.drawable.ddz, R.drawable.wb, R.drawable.tm,
R.drawable.uc,R.drawable.wx };
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ListView lv = (ListView) findViewById(R.id.listView1);
Myadapter md = new Myadapter();
lv.setAdapter(md);
}
class Myadapter extends BaseAdapter {
@Override
public int getCount() {
return t.length;
}
@Override
public Object getItem(int position) {
return t[position];
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view=View.inflate(MainActivity.this, R.layout.list_item, null);
TextView tv1=(TextView)view.findViewById(R.id.title);
ImageView iv=(ImageView)view.findViewById(R.id.iv);
tv1.setText(t[position]);
iv.setBackgroundResource(i[position]);
return view;
}
}
}
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
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="com.example.iop.MainActivity" >
<ListView
android:id="@+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="37dp" >
</ListView>
</RelativeLayout>
<?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="50dp"
android:layout_height="30dp"
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="15sp"
android:textColor="#000000" />
</RelativeLayout>
</RelativeLayout>
![](https://img2018.cnblogs.com/blog/1701021/201910/1701021-20191007132600181-1516266449.png)
![](https://img2018.cnblogs.com/blog/1701021/201910/1701021-20191007132629518-958681261.png)