Created
September 6, 2014 15:19
-
-
Save SZooo/f1d33a27c08a1bad4e8d to your computer and use it in GitHub Desktop.
list美化demo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<LinearLayout 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:background="#F0F0F0" | |
android:padding="5dp" | |
tools:context=".MainActivity" > | |
<ListView | |
android:id="@+id/list_view" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:dividerHeight="10dp" | |
android:divider="@drawable/divider" | |
android:listSelector="@drawable/list_selector" | |
android:cacheColorHint="#00000000"/> | |
</LinearLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<shape xmlns:android="http://schemas.android.com/apk/res/android" > | |
<solid android:color="#00000000"/> | |
<stroke android:color="#00000000" android:width="0px"/> | |
</shape> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<selector xmlns:android="http://schemas.android.com/apk/res/android"> | |
<item android:state_pressed="true"> | |
<shape> | |
<corners android:radius="2dp" /> | |
<solid android:color="#E8E8E8" /> | |
<stroke android:width="1px" android:color="#D8D4D8" /> | |
</shape> | |
</item> | |
<item android:state_pressed="false"> | |
<shape> | |
<corners android:radius="2dp" /> | |
<solid android:color="#FFFFFF" /> | |
<stroke android:width="1px" android:color="#D8D4D8" /> | |
</shape> | |
</item> | |
</selector> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:background="@drawable/list_selector" | |
android:orientation="vertical" > | |
<TextView | |
android:id="@+id/tv_item" | |
android:layout_width="match_parent" | |
android:layout_height="50dp" | |
android:gravity="center_vertical|left" | |
android:paddingLeft="10dp"/> | |
</LinearLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.evasion.listviewdemo; | |
import android.content.Context; | |
import android.view.LayoutInflater; | |
import android.view.View; | |
import android.view.ViewGroup; | |
import android.widget.BaseAdapter; | |
import android.widget.TextView; | |
import java.util.ArrayList; | |
import java.util.List; | |
public class ListAdapter extends BaseAdapter { | |
private List<String> list; | |
private Context context; | |
public ListAdapter(Context context) { | |
this.context = context; | |
list = new ArrayList<String>(); | |
for (int i = 0; i < 30; i++) { | |
list.add("data " + i); | |
} | |
} | |
@Override | |
public int getCount() { | |
return list.size(); | |
} | |
@Override | |
public Object getItem(int position) { | |
return list.get(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) { | |
holder = new ViewHolder(); | |
convertView = LayoutInflater.from(context).inflate(R.layout.list_item, null); | |
holder.tv = (TextView) convertView.findViewById(R.id.tv_item); | |
convertView.setTag(holder); | |
} else { | |
holder = (ViewHolder) convertView.getTag(); | |
} | |
holder.tv.setText(list.get(position)); | |
return convertView; | |
} | |
static class ViewHolder { | |
TextView tv; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.evasion.listviewdemo; | |
import android.app.Activity; | |
import android.os.Bundle; | |
import android.widget.ListView; | |
public class MainActivity extends Activity { | |
private ListView lv; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
lv = (ListView) findViewById(R.id.list_view); | |
lv.setAdapter(new ListAdapter(this)); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<resources> | |
<!-- | |
Base application theme, dependent on API level. This theme is replaced | |
by AppBaseTheme from res/values-vXX/styles.xml on newer devices. | |
--> | |
<style name="AppBaseTheme" parent="android:Theme.Light"> | |
<!-- | |
Theme customizations available in newer API levels can go in | |
res/values-vXX/styles.xml, while customizations related to | |
backward-compatibility can go here. | |
--> | |
</style> | |
<!-- Application theme. --> | |
<style name="AppTheme" parent="AppBaseTheme"> | |
<!-- All customizations that are NOT specific to a particular API-level can go here. --> | |
</style> | |
</resources> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment