How to round corners of a list view on Android

Asked 2 years ago, Updated 2 years ago, 145 views

I want to make the corners of the list round, what can I do?

android-listview android-layout android

2022-09-22 22:15

1 Answers

You can define and apply the xml of drawable.

res/drawable/customshape.xml

<?xml version="1.0" encoding="UTF-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
     android:shape="rectangle"> 
     <gradient 
         android:startColor="#SomeGradientBeginColor"
         android:endColor="#SomeGradientEndColor" 
         android:angle="270"/> 

    <corners 
         android:bottomRightRadius="7dp" 
         android:bottomLeftRadius="7dp" 
         android:topLeftRadius="7dp" 
         android:topRightRadius="7dp"/> 
</shape> 

Please define it like this and go to the list view In code, listView.setBackgroundResource(R.drawable.customshape); Like this.

If you want to give properties to xml, android:background="@drawable/customshape" You can do it in this way.


2022-09-22 22:15

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.