【发布时间】:2015-09-05 21:41:49
【问题描述】:
如果我想在布局的中心放置一张图片,我很容易使用:“垂直居中”和“水平居中”。但现在我想要一张图片将它放在左侧的中心。但我不想使用 marginLeft=..dp。我想在没有 dp 的情况下工作。有没有像“垂直居中”之类的可能性?这是带有 dp 值的代码。我可以用什么来代替 MarginLeft"38dp"?
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_centerInParent="true"
android:layout_marginLeft="41dp"
android:src="@drawable/rosezwei" />
</RelativeLayout>
【问题讨论】:
-
android:layout_centerInParent="true"? -
你的意思是像上面编辑过的帖子?
-
是的。那不行吗?
-
不,图片停留在布局的中心...
-
抱歉,问题看错了。也许更准确地解释你想要什么。您不希望它水平居中,并且您不想使用“dp”,无论这意味着什么,那么您想要什么 do 呢?我的意思是,如果您不想要边距,就不要使用边距。