Android 中的按钮是重叠的。需要修复

发布于 2024-12-02 03:23:12 字数 3843 浏览 5 评论 0原文

我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

夢归不見 2024-12-09 03:23:12

您使用的是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.

请别遗忘我 2024-12-09 03:23:12

使用 RelativeLayout 时,您应该使用 ALIGN_LEFTALIGN_RIGHTLEFT_OF 等以避免此类重叠。其他方法就是简单地使用LinearLayout

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文