回答
这个原因可能是你有不同的屏幕多个布局文件密度/屏幕尺寸/ android版本。
检查您的布局文件夹,并确保没有在多个文件夹中的多个lauout文件;)
看看你的XML定义:
<Button
android:text="Back"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/button5"
android:layout_toLeftOf="@+id/button2"
android:layout_toStartOf="@+id/progressBar2"
android:layout_marginRight="11dp"
android:layout_marginEnd="11dp"
android:layout_alignBottom="@+id/button2" />
<Button
android:text="Sign up"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="32dp"
android:id="@+id/button2"
android:layout_below="@+id/editText2"
android:layout_toRightOf="@+id/button5"
android:layout_toEndOf="@+id/progressBar2"
android:layout_marginLeft="14dp"
android:layout_marginStart="14dp" />
你立足的“符号的位置UP”按钮,将‘返回’按钮,通过此声明:
android:layout_toRightOf="@+id/button5"
我将让你正在使用隐藏button5
的假设,这反过来将实际上阻止button5
被绘制。
现在从您的布局中丢失,button2
将不再有依靠依据。从而使其一直转移到左侧。
的解决方案是非常简单的:使用View.INVISIBLE
而不是View.GONE
隐藏正在依靠另一个观点:
android:visibility="invisible"
如果:
如果您是通过XML隐藏它您通过Java以编程方式隐藏它:
button5.setVisibility(View.INVISIBLE);
您在xml布局中有circular dependancy
。
你不能/不应该做的事:
<Button
android:id="@+id/button5"
android:layout_toLeftOf="@+id/button2" />
<Button
android:id="@+id/button2"
android:layout_toRightOf="@+id/button5" />
设置其中之一的位置,并根据家长只(如alignParentLeft="true"
),然后就可以设置其它的基础上的位置第一个按钮。 Circular dependancies
有意想不到的结果,可能会在Studio
和Android
中显示不同的结果,或在Android
的不同版本中显示不同的结果。
我不确定为什么显示在android studio中是正确的,但快速浏览一下你的xml,你可以看到back button
和sign up button
的引用被搞砸了。请记住,相对布局使用具有view A
的概念,它可以作为的view B
位置的参考用,在你的XML您有:
<Button
android:text="Back"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/button5"
android:layout_toLeftOf="@+id/button2"
android:layout_toStartOf="@+id/progressBar2"
android:layout_marginRight="11dp"
android:layout_marginEnd="11dp"
android:layout_alignBottom="@+id/button2" />
<Button
android:text="Sign up"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="32dp"
android:id="@+id/button2"
android:layout_below="@+id/editText2"
android:layout_toRightOf="@+id/button5"
android:layout_toEndOf="@+id/progressBar2"
android:layout_marginLeft="14dp"
android:layout_marginStart="14dp" />
button5
引用button2
,反之亦然,这里的一个问题是你甚至不知道button2
是哪里,但你用它作为参考。另外,button5
取决于button2
的位置,但您使用button5
作为button2
的参考。
我建议使用editText2
作为您的两个按钮的参考,因为editText2
已确立其位置。使用android:layout_below="@+id/editText2"
,然后根据您的需要添加顶部边距。在此之后,使用
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
为返回键,使用
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
的注册按钮。然后你可以调整两个按钮的边距。
在xml布局中有一个循环依赖。
你可以看到
尝试这个
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin">
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
android:ems="10"
android:layout_marginTop="39dp"
android:id="@+id/editText"
android:hint="email"
android:textAlignment="center"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:ems="10"
android:layout_marginTop="47dp"
android:id="@+id/editText2"
android:hint="pass"
android:textAlignment="center"
android:layout_below="@+id/editText"
android:layout_alignLeft="@+id/editText"
android:layout_alignStart="@+id/editText" />
<Button
android:text="Back"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/button5"
android:layout_toStartOf="@+id/progressBar2"
android:layout_marginRight="11dp"
android:layout_marginEnd="11dp"
android:layout_alignBottom="@+id/button2"
android:layout_toLeftOf="@+id/progressBar2" />
<Button
android:text="Sign up"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="32dp"
android:id="@+id/button2"
android:layout_below="@+id/editText2"
android:layout_toEndOf="@+id/progressBar2"
android:layout_marginLeft="14dp"
android:layout_marginStart="14dp"
android:layout_toRightOf="@+id/progressBar2" />
<ProgressBar
style="?android:attr/progressBarStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="85dp"
android:id="@+id/progressBar2"
android:layout_below="@+id/button5"
android:layout_centerHorizontal="true" />
</RelativeLayout>
- 1. Android的布局,搞砸了的LinearLayout
- 2. CSS - 布局全搞砸了
- 3. Android布局搞砸了电话
- 4. 搞砸了Eclipse窗口布局
- 5. CSS布局完全搞砸了IE 11
- 6. vs2010窗口布局搞砸了
- 7. WinForms布局随机搞砸
- 8. html布局变得搞砸变焦
- 9. 我的Codeigniter .htaccess搞砸了吗?
- 10. 我搞砸了我的System_server服务吗?
- 11. 搞砸了android-studio和android-sdk
- 12. 搞砸了编码
- 13. -bash是搞砸了?
- 14. Linux bashrc搞砸了
- 15. laravel url搞砸了
- 16. OpenGL ES 1 + iOS 8 = layer.bounds搞砸了吗?
- 17. Bash配置文件搞砸了吗?
- 18. Jiggoshop产品页面搞砸了吗?
- 19. 搞砸了Jcrop的大小
- 20. 我真的搞砸了NPM
- 21. 流利的NuGet搞砸了
- 22. SSRS的CSS搞砸了?
- 23. CakePHP中找到搞砸了
- 24. bootstrap搞砸了形式
- 25. Bootstrap/CSS Div搞砸了CSS
- 26. VS SP1搞砸了MVC 3?
- 27. 模板函数搞砸了
- 28. Swift 3 UITableViewCell indexPath.row搞砸了
- 29. Rails3 + jQuery:Ajax响应搞砸了
- 30. Xcode编辑器搞砸了
你隐藏与可视性进度=到哪里去了?尝试使用可见性=不可见 –