问题描述
我有一个垃圾桶图标,正在ImageView中用作可绘制对象。 垃圾桶出现在我不需要的布局线的顶部(图1)。 添加'layout_gravity =“ bottom”'将图标一直向下移动到布局的底部(图片2)。 我希望将图标放置为与“到期日期”文本的水平底部完全匹配,并与到期日期EditText行(Pic3)末尾的左侧完全匹配。 我尝试增加边距和填充,但是没有运气。 有任何想法吗?
部分xml文件:
...
<LinearLayout
<ImageView
android:id="@+id/imageView1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_weight="1"
android:contentDescription="Trash can"
android:src="@drawable/ic_delete_black_24dp" />
...
图片1
图片2
图片3
图片4
1楼
试试吧:
trashIcon.setY(dateEdittext.getY-dateEdittext.getHeight/2);
2楼
您可以使用布局权重来确保垃圾箱只能使用所需的垃圾(0),并将其余垃圾提供给编辑文本(1)
<LinearLayout
<EditText
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
...
/>
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:scaleType="centerInside"
android:layout_weight="0"
android:contentDescription="Trash can"
android:src="@drawable/ic_delete_black_24dp" />
</LinearLayout>