2014-07-05 84 views
1

enter image description hereAndroid:稍微偏移ImageView中的图像

我们说下面的图像位于中央。为此,我使用下面的代码。

<RelativeLayout 
    android:layout_width="0dp" 
    android:layout_height="match_parent" 
    android:layout_weight="10" 
    android:orientation="vertical" > 
    <ImageView 
     android:src="@drawable/logo" 
     android:layout_centerInParent="true" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content"/> 
</RelativeLayout> 

它一直在为死亡中心定位。我想做以下事情,并稍微向上偏移它。正如你所看到的,我不想让图像穿过中心线(我知道如何通过添加一个不可见的视图来解决这个问题)。

enter image description here

回答

2

找到后给我一个提示,在假看法想法,使得假冒视图100dp长,假视图的底部填充100dp长(所以它可以下推),然后对准我的看法底部有假的底部,完美。

<RelativeLayout 
    android:layout_width="0dp" 
    android:layout_height="match_parent" 
    android:layout_weight="10" 
    android:orientation="vertical" > 
    <View 
     android:id="@+id/anchor" 
     android:layout_width="wrap_content" 
     android:layout_height="100dp" 
     android:layout_centerInParent="true" 
     android:paddingBottom="100dp" /> 

    <ImageView 
     android:src="@drawable/logo" 
     android:layout_alignBottom="@id/anchor" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content"/> 
</RelativeLayout> 
+0

谢谢你的工作完美。我甚至不需要锚点视图中的“paddingBottom”。 – Mike76