开发者

Buttons in android are overlapping. Need a fix

I am having some trouble with my xml file. Well it was working at first but the later I wanted to give it a scroll view so I added the scroll view on to the main.xml. After saving the file. The app used to crash without launching. Seeing this I removed the scroll view on the main.xml file, and am facing a new problem in which all of the buttons are being overlapped one another.

Also if you could tell me how can I give a scroll view tag correctly it would be helpful. Cheers. Thank you !

<?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>

This is the main xml file with the buttons overlapping.

<?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>

This is the main.xml with scroll view


You are using a RelativeLayout and not actually "placing" the buttons beside, or on top, or whatever of each other using something like the android:layout_toRightOf tags. The scrollview must be the parent view because it can only accept one child, which in your situation should be a LinearLayout (or a relative if your going to place your objects correctly). The main issue with your xml however is that RelativeLayout.


Using a RelativeLayout you should use ALIGN_LEFT, ALIGN_RIGHT, LEFT_OF etc in order to avoid such overlapping. Other way would be simply using LinearLayout.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜