RelativeLayout中两个控件怎么居中显示?
2017-08-19 16:34
615 查看
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<View
android:id="@+id/line"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_centerInParent="true" />
<Button
android:id="@+id/show"
android:layout_width="120dp"
android:layout_height="wrap_content"
android:layout_above="@id/line"
android:layout_centerHorizontal="true"
android:gravity="center"
android:paddingBottom="15dp"
android:text="演示" />
<Button
android:id="@+id/about"
android:layout_width="120dp"
android:layout_height="wrap_content"
android:layout_below="@id/line"
android:layout_centerHorizontal="true"
android:gravity="center"
android:paddingTop="5dp"
android:text="介绍" />
</RelativeLayout>
先设置一个View,让其居中,再设置另外两个控件,一个在它上面,一个在它下面。View是一个高为1dp的控件。
第二种方法是用一个LinearLayout将两个控件包起来,将LinearLayout设置为居中。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:orientation="vertical" >
<Button
android:id="@+id/show"
android:layout_width="120dp"
android:layout_height="wrap_content"
android:text="演示" />
<Button
android:id="@+id/about"
android:layout_width="120dp"
android:layout_height="wrap_content"
android:text="介绍" />
</LinearLayout>
</RelativeLayout>
第二种好使 第一种居中的前提是两个控件的长度相同
Url连接:http://bbs.csdn.net/wap/topics/390824491
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<View
android:id="@+id/line"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_centerInParent="true" />
<Button
android:id="@+id/show"
android:layout_width="120dp"
android:layout_height="wrap_content"
android:layout_above="@id/line"
android:layout_centerHorizontal="true"
android:gravity="center"
android:paddingBottom="15dp"
android:text="演示" />
<Button
android:id="@+id/about"
android:layout_width="120dp"
android:layout_height="wrap_content"
android:layout_below="@id/line"
android:layout_centerHorizontal="true"
android:gravity="center"
android:paddingTop="5dp"
android:text="介绍" />
</RelativeLayout>
先设置一个View,让其居中,再设置另外两个控件,一个在它上面,一个在它下面。View是一个高为1dp的控件。
第二种方法是用一个LinearLayout将两个控件包起来,将LinearLayout设置为居中。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:orientation="vertical" >
<Button
android:id="@+id/show"
android:layout_width="120dp"
android:layout_height="wrap_content"
android:text="演示" />
<Button
android:id="@+id/about"
android:layout_width="120dp"
android:layout_height="wrap_content"
android:text="介绍" />
</LinearLayout>
</RelativeLayout>
第二种好使 第一种居中的前提是两个控件的长度相同
Url连接:http://bbs.csdn.net/wap/topics/390824491
相关文章推荐
- RelativeLayout中两个控件怎么居中显示
- 如何让两个 TextView 在 RelativeLayout 中水平居中显示
- Android 让RelativeLayout布局中的控件居中显示
- RelativeLayout中放置两个控件后不能居中的问题
- DevExpress 在LayoutControl中放置控件保持布局居中显示
- 《转》QT界面怎么使控件随窗口大小变化一直居中显示
- Android - 在RelativeLayout中平分两个控件
- 两个TextView控件居中显示
- LinearLayout布局中控件居中显示
- android Relativelayout 某控件设置layout_alignParentRight=true,整行不显示问题
- 在RelativeLayout中对控件的显示隐藏操作问题
- android RelativeLayout里两控件间居中
- 有关RelativeLayout布局中, 当一个控件被左右两个控件夹在中间时, 此控件如何靠近两个控件中的一个的问题?
- relativeLayout中两个控件层次放置,但是能够透过上一层控件点击到下一层控件的问题
- RelativeLayout控件居中详细解析(可能是最完美的方法)
- 94.大于屏幕宽度的TableView上下拉刷新实现 大于屏幕宽度MJRefresh怎么实现刷新控件显示居中
- 在RelativeLayout中平分两个控件
- Android怎么让RadioButton图片居中显示
- 让两个DIV居中显示
- Android UI控件系列:RelativeLayout(相对布局)