android之layout_toLeftOf和layout_toRightOf出現的錯誤
阿新 • • 發佈:2019-01-05
錯誤是這樣的,佈局檔案如下,總是在SeekBar裡面的這一句android:layout_toLeftOf="@id/voice_max"報錯,差點氣得我吐血,明明沒有錯誤的.
<ImageView android:id="@+id/voice_min" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_centerVertical="true" android:background="@drawable/voice_min"/> <SeekBar android:id="@+id/sb_voice" android:layout_height="wrap_content" android:layout_width="fill_parent" android:layout_centerVertical="true" android:layout_toLeftOf="@id/voice_max" android:layout_toRightOf="@id/voice_min" android:paddingLeft="5dp" android:paddingRight="5dp" android:background="@drawable/voice_seekbar_bg" /> <ImageView android:id="@+id/voice_max" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_alignParentRight="true" android:layout_centerVertical="true" android:background="@drawable/voice_max"/>
後來我嘗試作了修改,如下
<ImageView android:id="@+id/voice_min" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_centerVertical="true" android:background="@drawable/voice_min"/> <ImageView android:id="@+id/voice_max" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_alignParentRight="true" android:layout_centerVertical="true" android:background="@drawable/voice_max"/> <SeekBar android:id="@+id/sb_voice" android:layout_height="wrap_content" android:layout_width="fill_parent" android:layout_centerVertical="true" android:layout_toLeftOf="@id/voice_max" android:layout_toRightOf="@id/voice_min" android:paddingLeft="5dp" android:paddingRight="5dp" android:background="@drawable/voice_seekbar_bg" />
錯誤就消失了,原來toLeftOf和toRightOf的引數需要在使用它們之前定義,
剛開始只想著從左到右的順序挨個寫,顯得有條理,看來我想多了.
錯誤就消失了,