_________________
| test |
| ______ |
|_____| |____|
|______|
这就是我想要的...更大的盒子是用可绘制对象制成的,里面有一个编辑文本。较小的框应该是带有上传图标的 ImageView 。
当编辑文本中没有任何内容时, ImageView 将消失(不可见)
_________________
| |
|_________________|
所以当图标可见时,我需要增加大框的宽度。大框也有一个笔划。
到目前为止我是这样的
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingStart="27dp"
android:paddingEnd="27dp"
android:paddingBottom="10dp"
android:paddingTop="10dp"
android:alpha=".5"
android:background="@drawable/commenting_drawable">
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="say something"
android:id="@+id/comments_editText"
android:textColor="@color/white"
android:textColorHint="@color/white_75"
android:fontFamily="sans-serif"
android:textSize="13sp"
android:textCursorDrawable="@null"
android:background="@color/transparent"
android:layout_centerInParent="true"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="35dp">
<ImageView
android:layout_width="40dp"
android:layout_height="40dp"
android:background="@drawable/icn_uploadcomment"
android:src="@drawable/black_circle_25"/>
</RelativeLayout>
</FrameLayout>
这是我的绘图
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid
android:color="#ff7c00" />
<stroke
android:width="1dp"
android:color="@color/white"/>
<corners
android:topLeftRadius="5dp"
android:topRightRadius="5dp"
android:bottomLeftRadius="5dp"
android:bottomRightRadius="5dp"/>
</shape>
所以基本上我希望 imagewiew 的一半位于 biggerbox 内,并且我想让 bigger box 在 ImageView 可见时自行调整。
最佳答案
您可以缩小图像相对布局的上边距大小,使其重叠。由于您可能已经有了代码来操纵布局,因为您正在使 ImageView 可见和不可见,因此更改较大框大小的最简单方法 (IMO) 是按如下方式调整填充:
RelativeLayout layout = (RelativeLayout) findViewById(R.id.biggerBox);
layout.setPadding(left, top, right, bottom);
left, top, right, bottom
将是更改较大框的大小所需的填充。 (您还需要为较大的盒子提供 ID。)
关于android - 布局中的一半 ImageView ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44757920/