Android 中的按钮是重叠的。需要修复
我的 xml 文件遇到一些问题。一开始它可以工作,但后来我想给它一个滚动视图,所以我将滚动视图添加到了 main.xml 中。保存文件后。该应用程序过去常常在未启动的情况下崩溃。看到这一点,我删除了 main.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"
>
<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
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您使用的是relativelayout,实际上并没有使用 android:layout_toRightOf 标签之类的东西将按钮“放置”在旁边、顶部或其他位置。滚动视图必须是父视图,因为它只能接受一个子视图,在您的情况下,该子视图应该是 LinearLayout (或者如果您要正确放置对象,则应该是相对的)。然而,您的 xml 的主要问题是relativelayout。
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.
使用
RelativeLayout
时,您应该使用ALIGN_LEFT
、ALIGN_RIGHT
、LEFT_OF
等以避免此类重叠。其他方法就是简单地使用LinearLayout
。Using a
RelativeLayout
you should useALIGN_LEFT
,ALIGN_RIGHT
,LEFT_OF
etc in order to avoid such overlapping. Other way would be simply usingLinearLayout
.