メイン ビューに (ループから) 何度か含めたい XML RelativeLayout スニペットがあります。問題は次のように思われます - RelativeLayout スニペットを含めるたびに要素に異なる ID が必要になるため、RatingBar の親のハードコーディングを回避する方法はありますか?
私が知る限り、推奨される方法は、レイアウト スニペットを取得し、各要素の android:id をオーバーライドして一意にし、相対位置を持つ各要素の android:layout_below を手動でオーバーライドすることです。これは少しぎこちないようです -- これらのバインディングを自動的に行う方法はありますか?
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:id="@+id/relativeView">
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:text="Label"
android:textAppearance="?android:attr/textAppearanceMedium" />
<RatingBar
android:id="@+id/ratingBar1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/textView1" />
</RelativeLayout>