我想有一个列表视图的外观这些行:如何自定义列表视图行
- 有圆角;
- 部分着色(每行的左侧部分);
- 在它们的着色区域中包含另一种颜色的形状。
下面是从其他应用程序的例子:
我现在有两条引线,但我没有对任何人的成功。
我的第一引线(形状)
我发现了如何通过使用形状来获得圆角,并用它作为列表视图的背景。
的绘制形状文件“rounded_rectangle.xml”:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<corners
android:bottomRightRadius="7dp"
android:bottomLeftRadius="7dp"
android:topLeftRadius="7dp"
android:topRightRadius="7dp"/>
</shape>
活动文件:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:custom="http://schemas.android.com/apk/res-auto"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:layout_width="match_parent"
android:layout_height="match_parent">
// ...
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/splitView"
android:id="@+id/lv_player"
android:layout_alignParentTop="true"
android:background="@drawable/rounded_rectangle"/>
// ...
</FrameLayout>
不过,我不知道如何使用的形状有一排部分着色或画一个图标。我可以用一种颜色填充形状,但这些行是完全着色的。
我的第二引线(矢量)
我还发现,我可以用一个向量作为我的列表视图的背景。好处是我可以使用路径绘制任何我想要的东西。
矢量文件的一个例子:
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:height="64dp"
android:width="64dp"
android:viewportHeight="600"
android:viewportWidth="600" >
<path
android:name="w"
android:fillColor="#000000"
android:pathData="m 290,103 l-200,0 c -50,0 -50,-100 0,-100 l200,0 z"
/>
</vector>
我可以轻松地创建为我行的彩色区域,另一个用于图标的路径。但是,现在的问题是我不知道如何将矢量的大小缩放到线的大小。
你知道什么是最好的选择,我如何获得预期的结果?
在此先感谢。