2016-03-29 5 views
0

Ich habe ein ImageView und ein TextView in RelativeLayout und I gesetzt layout_alignTop Attribut, aber wenn die Ansicht der Elemente angezeigt wird, sind nicht horizontal ausgerichtet.Artikel mit android: layout_alignTop haben noch Offset

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:background="#FFFFFF" 
    android:padding="10dp"> 
    <ImageView 
     android:id="@+id/iv_imageView" 
     android:layout_width="120dp" 
     android:layout_height="90dp" 
     android:src="@drawable/default_img" 
     android:layout_centerVertical="true" 
     android:scaleType="centerCrop" 
     android:contentDescription="@null"/> 
    <TextView 
     android:id="@+id/tv_pro_number" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="A123456" 
     android:paddingLeft="5dp" 
     android:paddingRight="6dp" 
     android:textSize="11sp" 
     android:layout_alignLeft="@id/iv_imageView" 
     android:layout_alignTop="@id/iv_imageView" 
     android:textColor="@color/white_color" 
     android:background="@drawable/back_line"/> 
.... 
</RelativeLayout> 

Ich benutze Dump View UI-Tool finden Sie die Offset-Daten. Es wird 1px oder 2px Offset geben.

screenshot

+1

try top padding von Textview auf 0 zu setzen. – hehe

Antwort

1

Versuchen Sie folgendes:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:orientation="vertical" android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="#FFFFFF" 
     android:padding="10dp"> 
     <ImageView 
      android:id="@+id/iv_imageView" 
      android:layout_width="120dp" 
      android:layout_height="90dp" 
      android:src="@drawable/marker" 
      android:layout_centerVertical="true" 
      android:scaleType="centerCrop" 
      android:contentDescription="@null"/> 
     <TextView 
      android:id="@+id/tv_pro_number" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="A123456" 
      android:paddingLeft="5dp" 
      android:paddingRight="6dp" 
      android:textSize="11sp" 
      android:layout_toRightOf="@+id/iv_imageView" 
      android:layout_alignTop="@id/iv_imageView" 
      android:textColor="@color/white" 
      /> 

..... 
     </RelativeLayout>