2014-01-28 3 views
0

В моем проекте я должен реализовать следующий дизайн. Это список отображаемых изображений и текста. Я использовал настраиваемый макет для раздувания строк.Fadded edge to Imageview in android

list item

list_background

Я поставил выше фона на странице элемента. Я установил прозрачный фон изображения. Но я не получил результат как изображение. Я получаю следующее изображение с URL-адреса. 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> 
+0

и Как Вам проблема на самом деле? – pskink

+0

Мне нужно показать изображение в соответствии с первым изображением. – Manikandan

+0

используйте LayerDrawable с двумя слоями: BitmapDrawable и GradientDrawable – pskink

ответ

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

Кстати, с 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);