Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/visual-studio/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在android中为图像添加左边框_Android_Android Layout_Android Xml - Fatal编程技术网

在android中为图像添加左边框

在android中为图像添加左边框,android,android-layout,android-xml,Android,Android Layout,Android Xml,是否可以将左边框指定给像“我的附加图像”中具有左条形边框的图像 我们需要将图像指定给边框,还是可以使用边框图像? 有人能帮忙吗 提前谢谢 以下是示例图像: 应用代码后的结果: 您可以通过创建一个版面而不是另一个版面,设置背景版面中所需的颜色,并在上部版面中添加一个左边距来轻松实现这一点。您可以通过以下方式轻松实现: 方法1-您不想重叠图像的一小部分: <LinearLayout android:layout_width="match_parent" android:lay

是否可以将左边框指定给像“我的附加图像”中具有左条形边框的图像

我们需要将图像指定给边框,还是可以使用边框图像? 有人能帮忙吗

提前谢谢

以下是示例图像:

应用代码后的结果:


您可以通过创建一个版面而不是另一个版面,设置背景版面中所需的颜色,并在上部版面中添加一个左边距来轻松实现这一点。

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

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

在您的布局文件中,如果您需要它在横向,只要做它的相同方向,你需要的,我已经附上了这一快照,请看一看


您能用一些代码详细说明一下吗?或者我可以使用图像作为边框吗?我没有电脑,我现在不能。好的,但没问题,但请稍后告诉我你是否可以这样做。是的,很好,这对我很有用。一个问题是,当我的图像高度增加时,它会工作吗?是的。这完全取决于父母的身高。你可以用一个固定的尺寸。我不建议根据图片的高度设置每个项目的高度。这会让你的应用看起来很糟糕。另一个关键组件是ImageView的scaleType属性。我只需应用您的代码并将结果粘贴到我的问题中,我想我们很接近了。请您提供更多帮助以解决此问题吗?我认为您的图像在顶部和底部有一个白色边框,这就是为什么它似乎无法正确放大的原因。如果愿意,可以使用scaleType属性。通过这种方式,您将了解它的行为:)实际上它与Scaltype属性一起工作,您的回答也很有用。太棒了,它非常适合我。非常感谢你。只需将Relativelayout更改为Linearlayout。Linearlayout会先查看一个视图,然后再查看另一个视图,其中作为相对布局覆盖了您的许多视图。不管怎样,njoy,如果您喜欢答案,请接受它。:)谢谢您的解释,我是android新手,所以:)您的wlcm随时都可以。:)