android中的Imageview褪色边缘

时间:2014-01-28 18:42:32

标签: android imageview

在我的项目中,我必须实现以下设计。它是要显示的图像和文本列表。我使用自定义布局来对行进行充气。

list item

list_background

我将上面的背景设置为项目页面。我将图像背景设置为透明。但我没有得到输出作为图像。 我从网址得到以下图片。 enter image description here

如何将设计作为第一张图像来实现。

我的项目xml是:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >


    <RelativeLayout
        android:id="@+id/item"
        android:layout_width="wrap_content"
        android:layout_height="100dp"
        android:background="@drawable/list_item_background" >

        <ImageView
            android:id="@+id/hotelimage"
            android:layout_width="200dp"
            android:layout_height="100dp"
            android:contentDescription="@string/img"
            android:scaleType="fitXY"
            android:background="#80000000"

           />

        <TextView
            android:id="@+id/hotelnametxt"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:textColor="@color/white"
            android:textStyle="bold"
            android:textSize="20sp" />

        <TextView

            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_toRightOf="@+id/hotelnametxt"
            android:text="@string/plus"
            android:textColor="@color/pink"
            android:textSize="20sp" />

        <ImageView
            android:id="@+id/tick1"
            android:layout_width="20dp"
            android:layout_height="20dp"
            android:layout_below="@+id/hotelnametxt"
            android:layout_marginLeft="80dp"
            android:layout_marginTop="15dp"
            android:contentDescription="@string/img"
            android:src="@drawable/tick_mark_normal" />

        <ImageView
            android:id="@+id/tick2"
            android:layout_width="20dp"
            android:layout_height="20dp"
            android:layout_below="@+id/hotelnametxt"
            android:layout_marginTop="15dp"
            android:layout_toRightOf="@id/tick1"
            android:contentDescription="@string/img"
            android:src="@drawable/tick_mark_normal" />

        <ImageView
            android:id="@+id/tick3"
            android:layout_width="20dp"
            android:layout_height="20dp"
            android:layout_below="@+id/hotelnametxt"
            android:layout_marginTop="15dp"
            android:layout_toRightOf="@+id/tick2"
            android:contentDescription="@string/img"
            android:src="@drawable/tick_mark_normal" />

        <ImageView
            android:id="@+id/tick4"
            android:layout_width="20dp"
            android:layout_height="20dp"
            android:layout_below="@+id/hotelnametxt"
            android:layout_marginTop="15dp"
            android:layout_toRightOf="@+id/tick3"
            android:contentDescription="@string/img"
            android:src="@drawable/tick_mark_normal" />

        <ImageView
            android:id="@+id/tick5"
            android:layout_width="20dp"
            android:layout_height="20dp"
            android:layout_below="@+id/hotelnametxt"
            android:layout_marginTop="15dp"
            android:layout_toRightOf="@+id/tick4"
            android:contentDescription="@string/img"
            android:src="@drawable/tick_mark_normal" />

        <TextView
            android:id="@+id/dollar"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/hotelnametxt"
            android:layout_marginLeft="180dp"
            android:layout_marginTop="5dp"
            android:textColor="@color/white"
            android:textSize="28sp" />

        <Button
            android:id="@+id/Viewbt"
            android:layout_width="80dp"
            android:layout_height="40dp"
            android:layout_below="@+id/hotelnametxt"
            android:layout_marginLeft="270dp"
            android:layout_marginTop="10dp"
            android:text="@string/precios"
            android:textSize="12sp" />

        <TextView
            android:id="@+id/title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="80dp"
            android:layout_marginTop="65dp"
            android:text="@string/direccion"
            android:textColor="@color/pink"
            android:textSize="12sp" />

        <TextView
            android:id="@+id/address"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/title"
            android:layout_marginLeft="80dp"
            android:layout_marginTop="3dp"
            android:singleLine="true"
            android:textColor="@color/white"
            android:textSize="12sp" />
    </RelativeLayout>

    <View
        android:id="@+id/dividerView"
        android:layout_width="fill_parent"
        android:layout_height="1dp"
        android:layout_below="@+id/item"
        android:background="@color/cyan" />

</RelativeLayout>

1 个答案:

答案 0 :(得分:0)

试试这个:

    final ImageView iv = new ImageView(this);
    int[] colors = {
            0x00000000, 0x66000000, 0xbb000000, 0xff000000, 0xff000000
    };
    Drawable[] layers = {
            getResources().getDrawable(R.drawable.layer0),
            new GradientDrawable(Orientation.LEFT_RIGHT, colors),
    };

    LayerDrawable ld = new LayerDrawable(layers);
    iv.setImageDrawable(ld);
    setContentView(iv);

btw,使用LayeredDrawable,你甚至可以做一些很好的事情:

    final ImageView iv = new ImageView(this);
    int[] colors = {
            0x00000000, 0x66000000, 0xbb000000, 0xff000000, 0xff000000
    };
    GradientDrawable gd = new GradientDrawable(Orientation.LEFT_RIGHT, colors);

    final ScaleDrawable sd = new ScaleDrawable(gd, Gravity.RIGHT | Gravity.FILL_VERTICAL, 1, 1);
    Drawable[] layers = {
            getResources().getDrawable(R.drawable.layer0),
            sd,
    };

    LayerDrawable ld = new LayerDrawable(layers);
    iv.setImageDrawable(ld);
    setContentView(iv);

    Runnable action = new Runnable() {
        @Override
        public void run() {
            int lvl = sd.getLevel();
            if (lvl < 10000) {
                sd.setLevel(lvl + 1000);
                iv.postDelayed(this, 40);
            }
        }
    };
    iv.postDelayed(action, 2000);