Androidプロジェクトにおいて、HTMLの"list-style-image"スタイルを適用したような、画像が1行目文字列の先頭につくタイプのリストを作成したいと考えています。
html
1<!DOCTYPE html> 2<html> 3<head> 4<style> 5ul { 6 list-style-image: url(star.svg); 7} 8</style> 9</head> 10<body> 11<ul> 12 <li>ListItem1<br>ListItem1</li> 13 <li>ListItem2<br>ListItem2</li> 14 <li>ListItem3<br>ListItem3<br>ListItem3</li> 15 <li>ListItem4<br>ListItem4</li> 16</ul> 17</body> 18</html>
今回はRemoteViews上のListViewで適用させたいため、FrameLayout、LinearLayout、RelativeLayoutといったごく基本のレイアウトしか使えず、また、ImageSpanなどのSpannableStringによる画像も利用できない(挿入しても無視される)、動的なレイアウト変更も基本的に不可という制限があります。
現時点では、アイコンのサイズを1行分のサイズに調整するためのLinearLayoutを配置し、このレイアウトの位置をもとに本文のTextViewを重ねる方法を考えてみたのですが、RelativeLayoutは親子関係にあるアイテムしか対象にならないようで、うまくいきませんでした。
xml
1<?xml version="1.0" encoding="utf-8" ?> 2<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 3 android:layout_width="match_parent" 4 android:layout_height="match_parent" 5 android:id="@+id/item_layout"> 6 7 <LinearLayout 8 android:orientation="horizontal" 9 android:layout_width="match_parent" 10 android:layout_height="wrap_content"> 11 <ImageView 12 android:layout_gravity="center" 13 android:background="@drawable/border" 14 android:id="@+id/item_icon" 15 android:scaleType="fitCenter" 16 android:src="@mipmap/ic_launcher" 17 android:layout_width="14dp" 18 android:layout_height="14dp"/> 19 <TextView 20 android:background="@drawable/border2" 21 android:id="@+id/item_line" 22 android:layout_alignParentTop="true" 23 android:layout_toRightOf="@id/item_icon" 24 android:layout_marginLeft="5dp" 25 android:layout_width="match_parent" 26 android:layout_height="wrap_content" 27 android:textColor="#FF0000" /> 28 </LinearLayout> 29 30 <TextView 31 android:id="@+id/item_text" 32 android:layout_width="match_parent" 33 android:layout_height="wrap_content" 34 android:layout_alignParentTop="true" 35 android:layout_marginLeft="5dp" 36 android:layout_toRightOf="@id/item_icon" 37 android:text="Main content for list item\nmultipleline" 38 android:textColor="#000000" /> 39</RelativeLayout>
良いレイアウト例がありましたら教えてください。