Android将图像放在RelativeLayout的顶部和中心

Android将图像放在RelativeLayout的顶部和中心,第1张

概述我正在尝试将图像与我的相对布局的顶部对齐,然后将其水平对齐.这是我正在使用的代码: <ImageView android:id="@+id/collection_image_background" android:layout_width="fill_parent" android:layout_height="fill_parent" 我正在尝试将图像与我的相对布局的顶部对齐,然后将其水平对齐.这是我正在使用的代码:
<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”,但它实际上是将图像左侧和顶部对齐的父级.

所以任何想法如何我可以正确对齐图像?

附:我忘了提到我正在将图像设置为我的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"  />
总结

以上是内存溢出为你收集整理的Android将图像放在RelativeLayout的顶部和中心全部内容,希望文章能够帮你解决Android将图像放在RelativeLayout的顶部和中心所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1137947.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-30
下一篇 2022-05-30

发表评论

登录后才能评论

评论列表(0条)

保存