为 android 中的图像添加左边框
Add left border to image in android
是否可以将左边框分配给像我的附加图像那样具有左条形边框的图像?
我们需要将图像分配给边框还是我们可以使用边框图像来完成?
有人可以帮忙吗?
提前致谢。
这是示例图片:
应用代码后的结果:
您可以通过在另一个布局之上创建一个布局、设置背景布局所需的颜色并为上层布局添加左边距来轻松实现此目的。
您可以通过以下方式轻松实现:
方法 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>
您始终可以只为 ImageView 设置背景颜色(或什至其他图像)并为其添加左内边距:
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#ff0000"
android:paddingLeft="20dp"
android:src="@drawable/image_res" />
试试这个,我已经做到了。
<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>
在你的布局文件中,如果你需要横向的,只要按照你需要的方向来做,我附上了一张截图,请看一下。
是否可以将左边框分配给像我的附加图像那样具有左条形边框的图像?
我们需要将图像分配给边框还是我们可以使用边框图像来完成? 有人可以帮忙吗?
提前致谢。
这是示例图片:
应用代码后的结果:
您可以通过在另一个布局之上创建一个布局、设置背景布局所需的颜色并为上层布局添加左边距来轻松实现此目的。
您可以通过以下方式轻松实现:
方法 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>
您始终可以只为 ImageView 设置背景颜色(或什至其他图像)并为其添加左内边距:
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#ff0000"
android:paddingLeft="20dp"
android:src="@drawable/image_res" />
试试这个,我已经做到了。
<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>
在你的布局文件中,如果你需要横向的,只要按照你需要的方向来做,我附上了一张截图,请看一下。