Here is my code(not all code,i have deleted some):
<RelativeLayout
android:id="@+id/info_in_my"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/head_in_my"
android:layout_marginTop="@dimen/spacing_size_36dp">
<ImageView
android:id="@+id/pic_in_my"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/spacing_size_36dp"
android:layout_alignParentStart="true"
android:src="@mipmap/icon_policeman" />
<TextView
android:id="@+id/name_in_my"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="AAAAAA"
android:layout_toEndOf="@id/pic_in_my"
android:layout_centerInParent="true"
android:textColor="@color/font_white"
android:textSize="@dimen/font_size_18sp" />
<TextView
android:id="@+id/organization_in_my"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="BBBBBBBBBBBBBBBBB"
android:layout_below="@+id/name_in_my"
android:layout_toEndOf="@+id/pic_in_my"
android:textSize="@dimen/font_size_12sp"
android:textColor="@color/font_white" />
</RelativeLayout>
This is the result:
I want String BBBBBBBBB
is below String AAAAAA
, so it's not right.
And i deleted android:layout_centerInParent="true"
in the first TextView
but no changes.
Is android:layout_below="@+id/name_in_my"
useless when First View
uses android:layout_centerInParent="true"
I want to know why?
To answer your question, "How to use layout_below in RelativeLayout?", check this example:
<Button android:id="@+id/b1"
.... />
<Button android:id="@+id/b2"
android:layout_below="@id/b1"
.... />
This means that you want button b2
to be below b1
. Note that I used @id
instead of @+id
because I already added the id b1
in my declaration of button b1
, thus, there is no reason to add it again.
Since you want BBBBB
below AAAA
, you have to put layout_below="id of AAAA"
in BBBB
.
android:layout_centerInParent
means that you want the view to be at the center of the parent, which in your case is the whole relative layout.
try below layout -
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/info_in_my"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/head_in_my"
android:layout_marginTop="@dimen/spacing_size_36dp"
>
<ImageView
android:id="@+id/pic_in_my"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/spacing_size_36dp"
android:layout_alignParentStart="true"
android:src="@drawable/ic_launcher"
/>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/pic_in_my"
android:layout_toEndOf="@+id/pic_in_my"
android:layout_alignParentTop="true"
android:layout_alignBottom="@+id/pic_in_my">
<TextView
android:id="@+id/name_in_my"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="AAAAAA"
android:layout_centerVertical="true"
android:textColor="@color/font_white"
android:textSize="@dimen/font_size_18sp"
/>
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="BBBBBBBBBBBBBBBBB"
android:textSize="@dimen/font_size_12sp"
android:textColor="@color/font_white"
android:layout_below="@+id/name_in_my"
android:layout_alignLeft="@+id/name_in_my"
android:layout_alignStart="@+id/name_in_my" />
</RelativeLayout>
</RelativeLayout>
使用toRightOf
代替toEndOf
在textviews
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.