android - 在android中为图像添加左边框

标签 android android-layout android-xml

是否可以将左边框分配给像我的附加图像那样具有左条形边框的图像?

我们需要将图像分配给 border 或者我们可以用 border image 来做? 任何人都可以帮忙吗?

提前致谢。

这是示例图片:

应用代码后的结果:

最佳答案

您可以通过以下方式轻松实现:

方法 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>

关于android - 在android中为图像添加左边框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33832714/

相关文章:

android - 如何在 Spotify Android 应用程序中自动播放播放列表

android - ActionBar 和 ListView 行之间的空间

android - android中editText的自定义背景

Android XML 解析器不解析

java - Android Studio 4.2 布局渲染错误

android - 如何在 Android 上创建 Preference Activity 和 Preference Fragment?

安卓 M : Effect of Selective Permissions on Ads

java - 单击列表项时 ViewPager 变为空白

android - 以编程方式获取指南百分比大小(以像素为单位)

android - 相机应用程序在 startActivityForResult 后崩溃