I'm trying to style the default ListView list divider to have margins of whitespace on both sides. I already tried to set the margins of the entire ListView but that didn't create the desired result.
What i have:
What i'm trying to make (notice the margins on both sides of the dividers):
What would be the best way of doing this? Thanks in advance!
use <include layout="@layout/divider" />
and custom layout for line. like this:
main.xml :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ListView android:id="@+id/listview"
android:layout_width="wrap_content"
android:divider="@layout/divider"
android:dividerHeight="3sp"
android:layout_height="wrap_content" />
</LinearLayout>
divider.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<gradient
android:startColor="#00000000"
android:centerColor="#FFFFFF"
android:endColor="#00000000" />
<corners
android:radius="4dp" />
</shape>
AndroidlistviewdividerActivity.class
public class AndroidlistviewdividerActivity extends Activity {
/** Called when the activity is first created. */
private ListView lv;
private String listview_array[] = { "ONE", "TWO", "THREE", "FOUR", "FIVE", "SIX",
"SEVEN", "EIGHT", "NINE", "TEN" };
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
lv = (ListView) findViewById(R.id.listview);
lv.setAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, listview_array));
lv.setTextFilterEnabled(true);
lv.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
// TODO Auto-generated method stub
AlertDialog.Builder adb = new AlertDialog.Builder(
AndroidlistviewdividerActivity.this);
adb.setTitle("ListView OnClick");
adb.setMessage("Selected Item is = "
+ lv.getItemAtPosition(arg2));
adb.setPositiveButton("Ok", null);
adb.show();
}
});
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With