【发布时间】:2014-07-13 01:56:45
【问题描述】:
当我运行应用程序并且三个文本视图被文本填充时,文本视图被重新排列并且整个布局被弄乱了。在 sdk 中,布局是应该的,但是一旦应用程序运行并且 textviews 被文本填充,布局就会变得混乱。我认为这与它是一个相对布局有关,但不确定。有人可以帮我解决这个问题吗?谢谢 这是我的 XML 代码:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background" >
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.firstapp.Menu$PlaceholderFragment" >
<TextView
android:id="@+id/txtView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:text="Main Menu"
android:textAppearance="?android:attr/textAppearanceLarge" />
android:id="@+id/button1"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/textView7"
android:layout_alignBottom="@+id/textView7"
android:layout_alignParentRight="true"
android:layout_marginRight="23dp"
android:text="Logout" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="200dip"
android:layout_below="@+id/textView5"
android:layout_centerHorizontal="true"
android:layout_marginTop="14dp"
android:text="Courses" />
<TextView
android:id="@+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toLeftOf="@+id/button2"
android:text="User Type:"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/name"
android:layout_alignLeft="@+id/textView4"
android:text="Name:"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/organization"
android:layout_alignBottom="@+id/organization"
android:layout_alignLeft="@+id/textView5"
android:text="Organization:"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/usertype"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/button2"
android:layout_alignRight="@+id/button2"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/organization"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/usertype"
android:layout_alignLeft="@+id/usertype"
android:layout_marginBottom="18dp"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/organization"
android:layout_below="@+id/txtView"
android:layout_marginTop="15dp"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
<Button
android:id="@+id/button1"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignTop="@+id/button2"
android:text="LogOut" />
【问题讨论】:
-
首先,button1 在其声明的开头缺少
-
在哪里?我在开始时看到
-
查看您帖子中的代码。使用 'textAppearance="?android:attr/textAppearanceLarge" />' 结束第一个 TextView 代码块后,您的下一行是 'android:id="@+id/button1"'
-
您在RelativeLayout 定义中做了同样的事情。您已在定义背景的第 5 行末尾关闭了块,因此所有关于填充等的行都将被忽略。
标签: java android xml android-layout