繁体   English   中英

菜单屏幕的布局被重新排列并弄乱了

[英]The layout of a menu screen gets rearranged and messed up

当我运行该应用程序时,三个文本视图被文本填充,这些文本视图被重新排列,整个布局被弄乱了。 在sdk中,布局是应该的样子,但是一旦应用程序运行且textview被文本填充时,布局就会混乱。 我认为这与相对布局有关,但不确定。 有人可以帮我解决这个问题吗? 谢谢这是我的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" />

在定义视图之前,您不应尝试在相对关系中使用视图。
例如,您在定义layout_alignLeft="@+id/textView4"之前,在layout_alignLeft="@+id/textView4"定义了layout_alignLeft="@+id/textView4"
相对布局对于构建灵活的布局很有用,但是您仍然需要以逻辑方式通过仅相对于现有视图定义新视图来构建它。

相对于根布局定义视图1。
相对于视图1或相对于根布局定义视图2。
相对于视图1、2或根布局定义视图3。
等等


额外:
这样想吧。 想象一个空表。

..我给您一个红色的方块,并告诉您将其放在桌子的中间。
..您这样做。

..我给您一个白色方块,并告诉您将其放在红色方块的右侧。
..再次,您这样做。

..我给您一个绿色的方块,并告诉您将其放在白色的方块上。
..再一次,没有问题。 你这样做

..我给您一个蓝色方块,并告诉您将其放在紫色方块的左侧。
..你说“我不能!这里没有紫色的块!”

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM