android中的按钮重叠。需要修复

问题描述:

我遇到了一些麻烦,我的XML文件。那么它一开始工作,但后来我想给它一个滚动视图,所以我将滚动视图添加到main.xml。保存文件后。该应用曾用于崩溃而不启动。看到这个我删除了main.xml文件中的滚动视图,并且遇到了一个新问题,即所有按钮都相互重叠。android中的按钮重叠。需要修复

此外,如果你能告诉我如何正确给出滚动视图标签,这将是有益的。 干杯。谢谢 !

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
> 

<TextView 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:text="Creating and Using Databases without Content Provider"/> 

<EditText 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:id="@+id/edit" 
android:padding="6dip"/> 

<EditText 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:id="@+id/msg" 
android:padding="6dip"/> 

<Button 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:text = "Add a new book" 
android:id="@+id/addTitle" 
android:padding="6dip"/> 

<Button 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:id="@+id/upTitle" 
android:text="Update a book" 
android:padding="6dip"/> 

<Button 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:id="@+id/rtrTitles" 
android:text="Retrieve all books" 
android:padding="6dip"/> 

<Button 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:id="@+id/rtrTitle" 
android:text="Retrieve Specific book" 
android:padding="6dip"/> 

<Button 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:id="@+id/delTitle" 
android:text="Delete a book" 
android:padding="6dip"/> 

<Button 
android:text="Send SMS" 
android:id="@+id/sms" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:padding="6dip"/> 

</RelativeLayout> 

这是按钮重叠的主要xml文件。

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
> 
<ScrollView 
android:layout_width="fill_parent" 
android:layout_height="fill_parent"> 
<TextView 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:text="Creating and Using Databases without Content Provider"/> 

<EditText 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:id="@+id/edit" 
android:padding="6dip"/> 

<EditText 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:id="@+id/msg" 
android:padding="6dip"/> 

<Button 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:text = "Add a new book" 
android:id="@+id/addTitle" 
android:padding="6dip"/> 

<Button 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:id="@+id/upTitle" 
android:text="Update a book" 
android:padding="6dip"/> 

<Button 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:id="@+id/rtrTitles" 
android:text="Retrieve all books" 
android:padding="6dip"/> 

<Button 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:id="@+id/rtrTitle" 
android:text="Retrieve Specific book" 
android:padding="6dip"/> 

<Button 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:id="@+id/delTitle" 
android:text="Delete a book" 
android:padding="6dip"/> 

<Button 
android:text="Send SMS" 
android:id="@+id/sms" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:padding="6dip"/> 
</ScrollView> 
</RelativeLayout> 

这是滚动视图main.xml中

+0

可能是http://stackoverflow.com/questions/4657687/relativelayout-scrollview的副本 – 2011-08-31 06:10:57

+0

RC我检查了你的链接..我的问题不是他的重复。 – Vinoth

+0

看起来对我来说只看到Nanee回答关于一个孩子,这个问题接受了答案。 – 2011-08-31 18:09:19

您正在使用的RelativeLayout并没有真正“放置”按钮的旁边,或者在上面,或任何的相互使用类似Android的: layout_toRightOf标签。 scrollview必须是父视图,因为它只能接受一个孩子,在你的情况下它应该是一个LinearLayout(如果你想正确放置你的对象的话,它应该是一个亲属)。然而,你的XML的主要问题是RelativeLayout。

使用RelativeLayout您应该使用ALIGN_LEFT,ALIGN_RIGHT, LEFT_OF等,以避免这种重叠。其他方式只需使用LinearLayout