I am developing an application which has a List View in it. I want each List View item to be round cornered. I have tried to do so but I failed to achieve my requirement instead of each item in List View the entire List View became round cornered and List items remained like a default List view items.Can anyone help me achieve my requirement.Below is my Layout files for List 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:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".list_activity"
android:background="@android:color/darker_gray">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:background="@drawable/listview_roundcorners">
<ListView
android:layout_width="322dp"
android:layout_height="446dp"
android:id="@+id/list"
android:layout_gravity="center_horizontal"
android:background="@drawable/border"
android:divider="@android:color/black"
android:dividerHeight="5dp"
android:clickable="true"
android:visibility="visible" />
</LinearLayout>
Here is the code for listview_roundcorners.xml in drawable folder which I am setting as the background for LinearLayout.
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:gradientandroid="http://schemas.android.com/tools"
xmlns:cornersandroid="http://schemas.android.com/apk/res-auto"
android:shape="rectangle">
<gradient
android:startColor="#aaa"
android:endColor="#aaa"
android:angle="270"/>
<corners
android:bottomRightRadius="7dp"
android:bottomLeftRadius="7dp"
android:topLeftRadius="7dp"
android:topRightRadius="7dp"/>
</shape>
Here is the code for border.xml in drawable folder which I am setting as background for my List View.
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<stroke android:width="1dp"
android:color="#FFFFFF" />
<padding android:left="5dp"
android:top="5dp"
android:right="5dp"
android:bottom="5dp" />
<corners android:radius="8dp" />
</shape>
my activity class is below
public class list_activity extends AppCompatActivity {
private ArrayAdapter<String> adapter;
private List<String> liste;
private ListView list;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_list_activity);
String[] values = new String[] { "Android", "iPhone", "WindowsMobile",
"Blackberry", "WebOS", "Ubuntu", "Windows7", "Max OS X",
"Linux", "OS/2" };
liste = new ArrayList<String>();
Collections.addAll(liste, values);
adapter = new ArrayAdapter<String>(this,
android.R.layout.select_dialog_multichoice, liste);
list = (ListView)findViewById(R.id.list);
list.setAdapter(adapter);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_list_activity, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}