请在相对布局中加入两个Button,使Button1水平居中显示且距离父控件顶部260dp,使Button2显示在Button1的右边且距离Button1底部100dp
时间: 2024-02-18 16:00:15 浏览: 31
可以使用如下布局代码实现:
```xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="260dp"
android:text="Button 1" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/button1"
android:layout_toEndOf="@+id/button1"
android:layout_marginStart="20dp"
android:layout_marginTop="100dp"
android:text="Button 2" />
</RelativeLayout>
```
解析:
- `Button1`:使用`layout_centerHorizontal`属性将其水平居中显示,使用`layout_marginTop`属性将其距离父控件顶部260dp。
- `Button2`:使用`layout_below`属性将其显示在`Button1`的下方,使用`layout_toEndOf`属性将其显示在`Button1`的右边,使用`layout_marginStart`属性控制其与`Button1`的间距,使用`layout_marginTop`属性将其距离`Button1`底部100dp。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)