开发者

Details of RelativeLayout in Android

开发者 https://www.devze.com 2022-12-19 01:55 出处:网络
What is the best documentation for the RelativeLayout layout algorithm? In the layout below, the edittext gets rendered on top of the textview. This seems

What is the best documentation for the RelativeLayout layout algorithm?

In the layout below, the edittext gets rendered on top of the textview. This seems wrong since the EditText has android:layout_below="@id/textview".

If I remove the android:layout_centerInParent="true" on the TextView, then the EditText is pushed below the TextView. Can anyone explain the algorithm that causes this to happen? Is this the intended behavior?

<?xml version="1.0" encoding="utf-8"?> 

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/ 
android"        android:layout_width="fill_parent" 
                android:layout_height="fill_parent" 
                android:id="@+id/main" 
        > 
    <RelativeLayout android:layout_width="wrap_content" 
                    android:layout_height="wrap_content" 
                    android:layout_centerInParent="true" 
                    android:id="@+id/inner" 
            > 
        <TextView 
                android:id="@+id/textview" 
                android:开发者_运维百科layout_centerInParent="true" 
                android:layout_width="wrap_content" 
                android:layout_height="wrap_content" 
                android:text="@string/hello" 
                /> 
        <EditText 
                android:layout_below="@id/textview" 
                android:id="@+id/textfield" 
                android:layout_width="wrap_content" 
                android:layout_height="wrap_content" 
                android:text="@string/hello" 
                /> 
    </RelativeLayout> 
</RelativeLayout> 


Not 100% sure about this, but what about the "+"-sign for the ID?

Also, why are you nesting RelativeLayouts? Thats what they're made for avoiding :)


From the relativeLayout docs:

Note that you cannot have a circular dependency between the size of the RelativeLayout and the position of its children. For example, you cannot have a RelativeLayout whose height is set to WRAP_CONTENT and a child set to ALIGN_PARENT_BOTTOM.

I think you may be running into this issue, try changing the layout_width and layout_height of your relative layout to fill_parent.

0

精彩评论

暂无评论...
验证码 换一张
取 消