簡體   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