2014-07-05 82 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