是否可以将左边框分配给图像,就像我的附加图像一样,它已经留下了条纹边框?
我们需要将图像分配到边框,或者我们可以使用边框图像进行分配吗? 有人可以帮忙吗?
提前致谢。
以下是示例图片:
应用代码后的结果:
答案 0 :(得分:2)
您可以通过以下方式轻松实现此目标:
方法1 - 您不希望重叠图像的那一小部分:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<View
android:layout_width="8dp"
android:layout_height="match_parent"
android:background="#FF0000" />
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:src="@drawable/my_image" />
</LinearLayout>
方法2 - 您希望将图像与边框重叠:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:src="@drawable/my_image" />
<View
android:layout_width="8dp"
android:layout_height="match_parent"
android:background="#FF0000" />
</RelativeLayout>
答案 1 :(得分:2)
试试这个,我已经做到了。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:src="@drawable/tcit" />
<View
android:layout_width="5dp"
android:layout_height="match_parent"
android:background="#336699" />
</RelativeLayout>
在您的布局文件中,如果您需要横向显示,只需按照您需要的相同方向进行操作,并为此附上快照,请仔细查看。
答案 2 :(得分:1)
您可以通过在另一个布局上创建一个布局,设置背景布局中所需的颜色并在上部布局中添加左边距来轻松实现此目的。
答案 3 :(得分:1)
您可以随时将背景颜色(甚至是其他图像)设置为ImageView并为其添加左边距:
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#ff0000"
android:paddingLeft="20dp"
android:src="@drawable/image_res" />