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