开发者

Why is there a gap when I alignTop?

Why is there a gap when I alignTop?

Why is there space between the top of the text and the top of the image??

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

<LinearLayout

    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_margin="9dp"
    android:background="#FFF">
    <RelativeLayout

        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_margin="9dp">
        <ImageView
            android:id="@+id/img_user"
            android:layout_width="30dp"
            android:layout_height="30dp"
            android:layout_marginRight="9dp开发者_开发问答"
            android:background="#000" />

        <TextView
            android:id="@+id/username"
            android:layout_toRightOf="@id/img_user"
            android:layout_alignTop="@id/img_user"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="#333"
            android:textStyle="bold"
            android:textSize="12dp"
            android:gravity="top"
            android:text="Username" />
        <TextView
            android:id="@+id/timestamp"
            android:layout_toRightOf="@id/img_user"
            android:layout_alignBottom="@id/img_user"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="#999"
            android:textSize="10dp"
            android:gravity="bottom" 
            android:text="2h"/>
    </RelativeLayout>


This is an inherent part of TextView. Try using margins, and consider wrapping extra layouts around to give you room to move things.


You have set a margin field in the linear layout and then again in the relative layout.

android:layout_margin="9dp"
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜