怎样使用android:layout_marginTop,离某元素上边缘的距离,这里怎样确定是里那个元素的距离

2025-01-30 15:10:25
推荐回答(4个)
回答1:

距离上方的距离,如果上方有组建就是指该组件,你的组建就会在你上面那个组建的下面,你应该用这个属性:android:layout_alignTop="@id/某个组件",这样你的组建就在这个组件的上面了,然后再距离这个多少距离就好了

回答2:

假如有一个button和一个textview,想要将textview放置在button下方,可以这样写
...
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="按钮" />
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_below="@+id/button1" //当前控件textview放置在button下方

android:layout_marginTop="20dp"
android:text="@string/hello_world" />

回答3:

这个你可以这样理解,如果你不设置这个属性,控件会有一个初始的位置,设置了以后等于向下平移了这么多的距离

回答4:

距离当前组件的上方的组件的距离