android xml上的重力属性不起作用
我刚开始安卓编程。我一直在android xml上的重力属性不起作用,android,xml,gravity,android-relativelayout,Android,Xml,Gravity,Android Relativelayout,我刚开始安卓编程。我一直在RelativeLayout中编写xml,发现gravity属性不起作用。布局中的每个元素都相互重叠。我知道可能有更好的方法进行定位,但我很想知道,我做的不正确是什么?请帮帮我 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
RelativeLayout
中编写xml,发现gravity
属性不起作用。布局中的每个元素都相互重叠。我知道可能有更好的方法进行定位,但我很想知道,我做的不正确是什么?请帮帮我
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/message"
android:gravity="start"
/>
<Button
android:id="@+id/btnclose"
android:textColor="#ffffff"
android:background="#780956"
android:textSize="18sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="close"
android:text="close"
android:gravity="bottom"
/>
<Button
android:id="@+id/btnclick"
android:textColor="#ffffff"
android:background="#123456"
android:textSize="18sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="close"
android:text="click"
android:gravity="center"
/>
</RelativeLayout>
使用RelativeLayout时,正确定位视图的方法是使用以下属性:
尝试这两种方法。使用RelativeLayout时,请按以下方式设置属性:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="message" />
<Button
android:id="@+id/btnclose"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#780956"
android:onClick="close"
android:text="close"
android:textColor="#ffffff"
android:textSize="18sp" />
<Button
android:id="@+id/btnclick"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#123456"
android:layout_centerInParent="true"
android:onClick="close"
android:text="click"
android:textColor="#ffffff"
android:textSize="18sp" />
</RelativeLayout>