Android 如何将安卓组件从中心偏移?

Android 如何将安卓组件从中心偏移?,android,xml,imageview,offset,centering,Android,Xml,Imageview,Offset,Centering,我想把我的imageview放在稍微高于中心的位置。我使用了centerHorizontal=“true”和paddingBottom,但它位于绝对中心。“填充”并不是工作。我该怎么办 <ImageView android:id="@+id/imageview" style="@style/myImageView" android:layout_width="200dp" android:layout_height="100dp" android:l

我想把我的imageview放在稍微高于中心的位置。我使用了centerHorizontal=“true”和paddingBottom,但它位于绝对中心。“填充”并不是工作。我该怎么办

<ImageView
    android:id="@+id/imageview"
    style="@style/myImageView"
    android:layout_width="200dp"
    android:layout_height="100dp"
    android:layout_centerHorizontal="true"
    android:paddingBottom="300dp"
    android:src="@drawable/ic_launcher" />


我希望您使用的是相对布局,而不是线性或绝对布局。

尝试使用布局:margin\u bottom。如果无法获得所需内容,请应用relativelayout和相同的bottom\u margin。

无法找到确切答案,但找到了另一种方法。我在相对布局中创建了一个框架布局,将imageview定位在其中,然后将重心设置为中心。 如果有更好的解决方案,请张贴。 我的代码:

在相对布局中--

我正在使用相对布局,但底部空白仍然不起作用。好的。我可以再给你一个建议,这是肯定有效的。但这不是一种优化的方式。它保留了额外的内存。创建一个假视图,它位于布局的中心,而可见性消失。现在在你的视图中,你想稍微高于中心,请将android:Layou置于上方=“@+id/id\u of_invisible view_,这是我们刚刚创建的位于中心的视图”。使用此技巧,您将得到您想要的。感谢您的想法。我在相对布局中创建了一个框架布局,定位了图像视图,然后将重心设置为中心。是的,我使用的是相对布局。
Inside the relative layout--
 <FrameLayout
    android:layout_width="800dp"
    android:layout_height="400dp"
    android:layout_alignParentRight="true"
    android:layout_alignParentBottom="true" 
    android:layout_marginRight="30dp"
    android:layout_marginBottom="100dp"

    >
    <ImageView
    android:id="@+id/imageview"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="center"
    android:src="@drawable/ic_launcher"
    style="@style/myImageView" />
</FrameLayout>