[英]Android align image in top and center in RelativeLayout
我正在尝试将图像对齐到相对布局的顶部,然后将其水平居中。 这是我正在使用的代码:
<ImageView
android:id="@+id/collection_image_background"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
,但是此代码无法正常工作。 我的图像居中,但未在“相对布局”的顶部对齐。 我尝试使用android:scaleType="fitStart"
,但实际上是将imag左对齐,并将其顶部对齐。
那么,有什么想法可以根据需要正确对齐图像吗?
PS我忘了提起我将图像设置为ImageView
如下所示:
BitmapFactory.Options o2 = new BitmapFactory.Options();
o2.inTempStorage = new byte[8*1024];
ops = BitmapFactory.decodeStream(cis,null,o2);
ImageView view = (ImageView) findViewById(R.id.collection_image_background);
view.setImageBitmap(ops);
代码似乎很完美,除了您已分配的内容区域fill_parent
占据了整个视图并将显示为中心,因此只需通过wrap_content
对其进行修改
<ImageView
android:id="@+id/collection_image_background"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.