2017-03-31 91 views
-2

元素始終顯示在屏幕頂部。我嘗試了不同的方法來修復,但運氣不好。我想將元素放置在屏幕的任何位置。這是碎片屏幕。元素始終顯示在分段屏幕的頂部。問題

<FrameLayout 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" 
    tools:context="myapp.com.myapp1.fragments.AddPeopleFragment"> 
    <TextView 
     android:id="@+id/textView1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     tools:layout_editor_absoluteX="8dp" 
     tools:layout_editor_absoluteY="159dp" 
     android:text="three" 
     android:layout_alignParentTop="true" 
     android:layout_alignParentStart="true" 
     android:layout_marginStart="110dp" 
     android:layout_marginTop="167dp" /> 
</FrameLayout> 

回答

0

你有沒有注意到這些代碼行?

"android:layout_alignParentTop="true" 
    android:layout_alignParentStart="true"" 

如果你想使用絕對佈局,不要打擾這些代碼;

如:

<FrameLayout 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" 
tools:context="myapp.com.myapp1.fragmants.FragmantAddPeople"> 
<TextView 
    android:id="@+id/textView1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    tools:layout_editor_absoluteX="8dp" 
    tools:layout_editor_absoluteY="159dp" 
    android:text="three" 

    android:layout_marginStart="110dp" 
    android:layout_marginTop="167dp" /> 
    </android.support.constraint.ConstraintLayout> 

您可以將項目(在案件的按鈕),通過改變absoluteX和absoluteY的DP值的任何地方;``

+1

仍然沒有工作。我用了你給我的同樣的例子。 – Jason

+0

順便說一句,你打開了一個'FrameLayout'並關閉了一個'ConstraintLayout' ... –

+0

如果你不在RelativeLayout中,alignParent屬性完全沒有效果,並且layout_editor屬性只會影響編輯器預覽。你應該使用marginStart/Left和marginTop –