Fadded边缘的ImageView android系统 [英] Fadded edge to Imageview in android

查看:209
本文介绍了Fadded边缘的ImageView android系统的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的项目,我要实现以下的设计。它是图像和文字来显示列表。我用了一个自定义布局膨胀行。

我设置在上述背景下,以该项目的页面。我的图片背景设置为透明。但我没有得到的输出作为图像之一。
我从网址下面的图像。

如何才能达到设计的第一张图像。

和我的项目XML是:

 <?XML版本=1.0编码=UTF-8&GT?;
<的RelativeLayout的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:layout_width =match_parent
    机器人:layout_height =match_parent
    机器人:方向=垂直>
    < RelativeLayout的
        机器人:ID =@ + ID /项
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =100dp
        机器人:背景=@绘制/ list_item_background>        < ImageView的
            机器人:ID =@ + ID / HotelImage概要
            机器人:layout_width =200dp
            机器人:layout_height =100dp
            机器人:contentDescription =@字符串/ IMG
            机器人:scaleType =fitXY
            机器人:背景=#8000           />        <的TextView
            机器人:ID =@ + ID / hotelnametxt
            机器人:layout_width =WRAP_CONTENT
            机器人:layout_height =WRAP_CONTENT
            机器人:layout_marginLeft =10dp
            机器人:文字颜色=@色/白
            机器人:文字样式=大胆
            机器人:TEXTSIZE =20SP/>        <的TextView            机器人:layout_width =WRAP_CONTENT
            机器人:layout_height =WRAP_CONTENT
            机器人:layout_toRightOf =@ + ID / hotelnametxt
            机器人:文字=@字符串/加
            机器人:文字颜色=@色/粉
            机器人:TEXTSIZE =20SP/>        < ImageView的
            机器人:ID =@ + ID / tick1
            机器人:layout_width =20dp
            机器人:layout_height =20dp
            机器人:layout_below =@ + ID / hotelnametxt
            机器人:layout_marginLeft =80dp
            机器人:layout_marginTop =15dp
            机器人:contentDescription =@字符串/ IMG
            机器人:SRC =@绘制/ tick_mark_normal/>        < ImageView的
            机器人:ID =@ + ID / tick2
            机器人:layout_width =20dp
            机器人:layout_height =20dp
            机器人:layout_below =@ + ID / hotelnametxt
            机器人:layout_marginTop =15dp
            机器人:layout_toRightOf =@ ID / tick1
            机器人:contentDescription =@字符串/ IMG
            机器人:SRC =@绘制/ tick_mark_normal/>        < ImageView的
            机器人:ID =@ + ID / tick3
            机器人:layout_width =20dp
            机器人:layout_height =20dp
            机器人:layout_below =@ + ID / hotelnametxt
            机器人:layout_marginTop =15dp
            机器人:layout_toRightOf =@ + ID / tick2
            机器人:contentDescription =@字符串/ IMG
            机器人:SRC =@绘制/ tick_mark_normal/>        < ImageView的
            机器人:ID =@ + ID / tick4
            机器人:layout_width =20dp
            机器人:layout_height =20dp
            机器人:layout_below =@ + ID / hotelnametxt
            机器人:layout_marginTop =15dp
            机器人:layout_toRightOf =@ + ID / tick3
            机器人:contentDescription =@字符串/ IMG
            机器人:SRC =@绘制/ tick_mark_normal/>        < ImageView的
            机器人:ID =@ + ID / tick5
            机器人:layout_width =20dp
            机器人:layout_height =20dp
            机器人:layout_below =@ + ID / hotelnametxt
            机器人:layout_marginTop =15dp
            机器人:layout_toRightOf =@ + ID / tick4
            机器人:contentDescription =@字符串/ IMG
            机器人:SRC =@绘制/ tick_mark_normal/>        <的TextView
            机器人:ID =@ + ID /美元
            机器人:layout_width =WRAP_CONTENT
            机器人:layout_height =WRAP_CONTENT
            机器人:layout_below =@ + ID / hotelnametxt
            机器人:layout_marginLeft =180dp
            机器人:layout_marginTop =5DP
            机器人:文字颜色=@色/白
            机器人:TEXTSIZE =28sp/>        <按钮
            机器人:ID =@ + ID / Viewbt
            机器人:layout_width =80dp
            机器人:layout_height =40dp
            机器人:layout_below =@ + ID / hotelnametxt
            机器人:layout_marginLeft =270dp
            机器人:layout_marginTop =10dp
            机器人:文字=@字符串/ precios
            机器人:TEXTSIZE =12SP/>        <的TextView
            机器人:ID =@ + ID /标题
            机器人:layout_width =WRAP_CONTENT
            机器人:layout_height =WRAP_CONTENT
            机器人:layout_marginLeft =80dp
            机器人:layout_marginTop =65dp
            机器人:文字=@字符串/ direccion
            机器人:文字颜色=@色/粉
            机器人:TEXTSIZE =12SP/>        <的TextView
            机器人:ID =@ + ID /地址
            机器人:layout_width =WRAP_CONTENT
            机器人:layout_height =WRAP_CONTENT
            机器人:layout_below =@ + ID /标题
            机器人:layout_marginLeft =80dp
            机器人:layout_marginTop =3DP
            机器人:单线=真
            机器人:文字颜色=@色/白
            机器人:TEXTSIZE =12SP/>
    < / RelativeLayout的>    <查看
        机器人:ID =@ + ID / dividerView
        机器人:layout_width =FILL_PARENT
        机器人:layout_height =1DP
        机器人:layout_below =@ + ID /项
        机器人:背景=@色/青色/>< / RelativeLayout的>


解决方案

试试这个:

 最后的ImageView IV =新ImageView的(本);
    INT [] =颜色{
            00000000,0x66000000,0xbb000000,0xff000000,0xff000000
    };
    可绘制[] =层{
            getResources()。getDrawable(R.drawable.layer0)
            新GradientDrawable(Orientation.LEFT_RIGHT,颜色),
    };    LayerDrawable LD =新LayerDrawable(层);
    iv.setImageDrawable(LD);
    的setContentView(四);

顺便说一句,与LayeredDrawable你甚至可以做一些好东西这样的:

 最后的ImageView IV =新ImageView的(本);
    INT [] =颜色{
            00000000,0x66000000,0xbb000000,0xff000000,0xff000000
    };
    GradientDrawable GD =新GradientDrawable(Orientation.LEFT_RIGHT,颜色);    最后ScaleDrawable SD =新ScaleDrawable(GD,Gravity.RIGHT | Gravity.FILL_VERTICAL,1,1);
    可绘制[] =层{
            getResources()。getDrawable(R.drawable.layer0)
            SD,
    };    LayerDrawable LD =新LayerDrawable(层);
    iv.setImageDrawable(LD);
    的setContentView(四);    可运行动作=新的Runnable(){
        @覆盖
        公共无效的run(){
            INT LVL = sd.getLevel();
            如果(LVL< 10000){
                sd.setLevel(LVL + 1000);
                iv.postDelayed(此,40);
            }
        }
    };
    iv.postDelayed(动作,2000年);

In my project, I have to implement the following design. It is a list of images and text to display. I used a custom layout to inflate the rows.

I set the above background to the item page. I set the image background to transparent. But I didn't get the output as the image one. I get the following image from the url.

How can achieve the design as the first image.

And my item xml is:

<?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>

解决方案

try this:

    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, with LayeredDrawable you can even do some nice things like that:

    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);

这篇关于Fadded边缘的ImageView android系统的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆