android - Offsetting an overlay in Android
问题描述
I have an ImageView with a background and a src. The background is sized (for xxxhdpi) 111x111 and the src is sized (again, for xxxhdpi) as 27x34.
I would like the src image to display in the upper right, and be sized correctly (smaller) but what I am seeing now is that it centers and expands to the size of the background image.
Do I need to make the src the same size as the background and add a transparent background to the lower left perhaps?
Here is what I have so far.
<ImageView android:layout_width="80dp"
android:layout_height="80dp"
android:id="@+id/autoButton"
android:background="@drawable/automode"
android:src="@drawable/lock_icn"
android:layout_marginBottom="15dp"
android:textColor="@color/grey_400"
android:text="@string/auto_mode"
/>
Thanks.
解决方案
最终变得非常像上面提到的那样。这是为了完整性。
<FrameLayout
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_marginBottom="15dp"
android:layout_marginTop="10dp"
android:background="@drawable/automode"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:text="@string/auto_mode"
android:textColor="@color/grey_400"
android:textSize="17sp" />
<ImageView android:layout_width="20dp"
android:layout_height="20dp"
android:layout_gravity="end"
android:id="@+id/deleteButton"
android:src="@drawable/lock_icn"
/>
</FrameLayout>
推荐阅读
- java - 仅当涉及文件 iploads/downloads 时才阻止跨域请求
- ssl - Opencart SLL httpaccess
- android - API 23 中的 ContextCompat.getColor 崩溃(未找到 Context.getColor)
- javascript - 如何使用 jquery 设置选择选项值并选择搜索库?
- python - 两个数据集的python热图
- regex - 提取第一次出现的数字和文件名的最后一个单词
- amazon-rds - 在创建快照期间重新启动 aws rds
- c# - 将值列表从 mvc 模型分组到 html 表
- r - 小鼠:拆分估算数据以进行进一步分析
- javascript - Puppeteer - 在框架内运行函数