layout_marginLeftが悪さをする?→(解決)
直列化とコレクション、永続化 - mixi-inc/AndroidTraining
の「コレクション・直列化」の課題2
activity_main.xmlの中で
<LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Status" /> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="20dp" android:text="PostedTime" /> <TextView android:id="@+id/user_postedTime" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="right"/> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="20dp" android:text="Text" /> <TextView android:id="@+id/user_text" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="right"/> </LinearLayout> </LinearLayout>
と記述したのだが、2箇所記述している「android:layout_marginLeft="20dp"」があると正常表示されない。
無くすと、正常表示される。
なぜ余白を入れると正常/異常が変わるのか分からない
marginLeftの行を削除してandroid:textを" Text"などと空白を入れてインデントしたが、どうも釈然としない。
えらい時間を取られた。
---
追記(現象解決)
android:layout_width="wrap_content"にして
android:layout_weight="1"をつけると
android:layout_marginLeft="20dp"を指定しても正常表示された。