我在下面有這個簡單的 xml。問題是layout_marginLeft,layout_marginRight或layout_marginTop都layout_marginBottom不起作用。但是layout_margin有效!
<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:layout_marginLeft="16dp" <-- does not work
android:layout_marginTop="16dp" <-- does not work
android:text="This is a text!"
/>
</LinearLayout>
另外,我注意到當我添加一個不完整的layout_margin="0"(沒有 dp)時,它會導致錯誤,但是marginLeft,marginRight等可以正常作業!但后來我有一個錯誤,它不會編譯。這里發生了什么?!
uj5u.com熱心網友回復:
找到罪魁禍首!原來我有這條線themes.xml
<item name="android:layout_margin">2dp</item>
這搞砸了所有的layout_margin電話。洗掉了這條線,現在邊距可以正常作業。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/438113.html
上一篇:ScrollView底部的按鈕,里面有ListView
下一篇:使用引數更新記憶值
