************效果图*****************
**********activity.xml***************
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#030303"
>
<ImageView
android:id="@+id/iv_bg"
android:layout_width="290dp"
android:layout_height="290dp"
android:layout_centerHorizontal="true"
android:src="@drawable/bg" />
<LinearLayout
android:layout_width="290dp"
android:layout_height="230dp"
android:layout_alignLeft="@+id/iv_bg"
android:layout_below="@+id/iv_bg"
android:orientation="vertical"
android:background="#FFF68F"
>
<EditText
android:id="@+id/et_name"
android:layout_width="240dp"
android:layout_height="wrap_content"
android:background="#FFFFFF"
android:hint="请输入用户名"
android:textSize="20sp"
android:layout_marginTop="10dp"
android:padding="5dp"
android:layout_gravity="center_horizontal"
android:drawableLeft="@drawable/user"
/>
<EditText
android:id="@+id/et_pwd"
android:layout_width="240dp"
android:layout_height="wrap_content"
android:background="#FFFFFF"
android:hint="请输入密码"
android:textSize="20sp"
android:layout_marginTop="10dp"
android:padding="5dp"
android:layout_gravity="center_horizontal"
android:drawableLeft="@drawable/pwd_lock"
/>
<CheckBox
android:id="@+id/cb_pwd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="记住密码"
android:layout_marginLeft="25dp"
android:layout_marginTop="10dp"
android:button="@drawable/checkbox_presed"
/>
<ImageView
android:id="@+id/iv_login"
android:layout_width="100dp"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
android:layout_marginTop="5dp"
android:src="@drawable/btn_login_normal"
/>
</LinearLayout>
</RelativeLayout>
MainActivity***********代码如下***********
···
package com.example.loginjishi;
import java.util.Timer;
import java.util.TimerTask;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.text.format.Time;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Toast;
public class MainActivity extends Activity {
private ImageView iv_login;
private EditText et_name;
private EditText et_pwd;
private CheckBox cb_pwd;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
iv_login=(ImageView) findViewById(R.id.iv_login);
iv_login.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// String useName = et_name.getText().toString().trim();
// String usePwd = et_pwd.getText().toString().trim();
Toast.makeText(MainActivity.this, "登陆", Toast.LENGTH_SHORT).show();
startActivity(new Intent(MainActivity.this,SecondActivity.class));
}
});
}
}
···
**************效果图*************
我们定义一个Item.xml*************
代码如下:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="100dp"
android:orientation="horizontal"
>
<ImageView
android:id="@+id/iv_1"
android:layout_width="80dp"
android:layout_height="match_parent"
android:src="@drawable/user"
android:layout_marginLeft="5dp"
/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/tv_1"
android:layout_width="160dp"
android:layout_height="wrap_content"
android:gravity="center"
android:text="张三"
android:textSize="20sp"
android:layout_marginTop="20dp"
/>
<TextView
android:id="@+id/tv_2"
android:layout_width="160dp"
android:layout_height="wrap_content"
android:gravity="center"
android:text="身高:188cm"
android:textColor="#4B0082"
android:textSize="10sp"
android:layout_marginTop="10dp"
/>
<TextView
android:id="@+id/tv_3"
android:layout_width="160dp"
android:layout_height="wrap_content"
android:gravity="center"
android:text="体重:200kg"
android:textSize="10sp"
android:textColor="#4B0082"
android:layout_marginTop="5dp"
/>
</LinearLayout>
<ImageView
android:id="@+id/iv_2"
android:layout_width="120dp"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:src="@drawable/arrows" />
</LinearLayout>
</LinearLayout>
****activity_second.xml**********代码如下********
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="移动软件学院学员"
android:background="#A52A2A"
android:gravity="center"
android:textSize="20sp"
/>
<ListView
android:id="@+id/lv_id"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/bb"
>
</ListView>
</LinearLayout>
同时创建一个Student类保存信息继承BaseAdapter
*************代码如下*******
···
package com.example.loginjishi;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
public class StudnetAdapter extends BaseAdapter{
private int [] icons ;
private String[] names;
private Context context;
public StudnetAdapter() {
super();
}
public StudnetAdapter(Context context,int[] icons, String[] names) {
super();
this.icons = icons;
this.names = names;
this.context = context;
}
@Override
public int getCount() {
return names.length;
}
@Override
public Object getItem(int position) {
return names[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(context,R.layout.item_second, null);
holder= new ViewHolder();
holder.imageView = (ImageView) convertView.findViewById(R.id.iv_1);
holder.imageView2 = (ImageView) convertView.findViewById(R.id.iv_1);
holder.textView1 = (TextView) convertView.findViewById(R.id.tv_1);
holder.textView2 = (TextView) convertView.findViewById(R.id.tv_2);
holder.textView3 = (TextView) convertView.findViewById(R.id.tv_3);
convertView.setTag(holder);
} else {
holder=(ViewHolder) convertView.getTag();
}
holder.imageView.setImageResource(icons[position]);
holder.imageView2.setImageResource(icons[position]);
holder.textView1.setText(names[position]);
holder.textView2.setText(names[position]);
holder.textView3.setText(names[position]);
return convertView;
}
class ViewHolder{
ImageView imageView;
ImageView imageView2;
TextView textView1;
TextView textView2;
TextView textView3;
}
}
···
SecondActivity***************代码如下***********
···
package com.example.loginjishi;
import java.util.ArrayList;
import java.util.List;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemLongClickListener;
import android.widget.ListView;
public class SecondActivity extends Activity {
private ListView lv_id;
private StudnetAdapter adapter;
String [] names=new String[]{"张三\n身高:188cm\n体重:200kg",
"张三\n身高:188cm\n体重:200kg","张三\n身高:188cm\n体重:200kg",
"张三\n身高:188cm\n体重:200kg","张三\n身高:188cm\n体重:200kg","张三\n身高:188cm\n体重:200kg",
"张三\n身高:188cm\n体重:200kg","张三\n身高:188cm\n体重:200kg","张三\n身高:188cm\n体重:200kg"
,"张三\n身高:188cm\n体重:200kg"};
int [] icons=new int[]{R.drawable.user,
R.drawable.user,R.drawable.user,
R.drawable.user,R.drawable.user,R.drawable.user,
R.drawable.user,R.drawable.user,R.drawable.user,R.drawable.user};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
lv_id=(ListView) findViewById(R.id.lv_id);
adapter = new StudnetAdapter(SecondActivity.this,icons,names);
lv_id.setAdapter(adapter);
lv_id.setOnItemLongClickListener(new OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view,
int position, long id) {
new AlertDialog.Builder(SecondActivity.this)
.setTitle("警告")
.setMessage("你没有删除权限!")
.setNegativeButton("取消", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
}).show();
return false;
}
});
}
}
···