【发布时间】:2020-10-14 15:06:48
【问题描述】:
我正在做一个项目,我想在其中开始引入视图绑定 其中一个布局看起来是这样的,布局重用了 id 出于某种我不明白的原因,我暂时无法重构它
<LinearLayout
android:layout_width="match_parent"
android:layout_height="@dimen/tip_height"
android:layout_marginLeft="50dp"
android:layout_marginRight="50dp"
android:layout_marginTop="20dp"
android:orientation="horizontal"
android:id="@+id/TipContainer">
<LinearLayout
style="@style/TipButtonNeatLeft"
android:id="@+id/TipButtonNone">
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/TipButtonTitle"
style="@style/ResizableTipButton.Title"
android:layout_width="match_parent"
android:layout_height="@dimen/tip_title_height"
android:text="@string/tip_signature_notip"/>
</LinearLayout>
<LinearLayout
style="@style/TipButtonNeat"
android:id="@+id/TipButton1">
<androidx.appcompat.widget.AppCompatTextView
android:id="@id/TipButtonTitle"
style="@style/ResizableTipButton.Title"
android:layout_width="match_parent"
android:layout_height="@dimen/tip_signature_tip_option_title_height"
android:text="@string/tip_signature_15percent"/>
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/TipButtonSubTitle"
style="@style/ResizableTipButton.Subtitle"
android:layout_width="match_parent"
android:layout_height="@dimen/tip_signature_tip_option_subtitle_height"
tools:text="$4.99"/>
</LinearLayout>
</LinearLayout>
我不断收到此错误TipButtonTitle conflicts with another tag that has the same ID
我尝试在我的根视图上使用tools:viewBindingIgnore="true",但没有运气
任何建议如何在无需更改 ID 的情况下消除该错误
【问题讨论】:
-
ViewBinding 需要为每个视图设置一个唯一的视图 ID。
标签: android android-layout android-viewbinding