0

please help me with this. I have tried a lot of things and even the response here How to show Text on Image but not getting the desired output as shown in the first image of that page. I am trying to display images with text overlay. I got a code to load the image with a Lazy Adapter. But the images being displayed are padded on both sides. Here is what i'm getting

Here are my codes:

the tile layout xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">

        <ImageView
            android:id="@+id/tileimage"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:contentDescription="@string/logo"
             />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_alignParentBottom="true"
            android:orientation="vertical" >


            <TextView
                android:id="@+id/tilecontent"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:textColor="#FFF"
                android:textSize="16sp"
                android:textStyle="bold"
                android:background="#55000000" />
        </LinearLayout>
</RelativeLayout>

the grid layout

<FrameLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<GridView
    android:id="@+id/gridview"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:verticalSpacing="1dp"
    android:horizontalSpacing="1dp"
    android:stretchMode="columnWidth"
    android:numColumns="2" 
    />
</FrameLayout> 

I'm inflating the tiles from here

public class LazyAdapter extends BaseAdapter {

private Activity activity;
private String[] content;
private static LayoutInflater inflater=null;
public ImageLoader imageLoader; 

public LazyAdapter(Activity act, String[] cont) {
    activity = act;
    content = cont;
    inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    imageLoader = new ImageLoader(activity.getApplicationContext());
}

public int getCount() {
    return content.length;
}

public Object getItem(int position) {
    return position;
}

public long getItemId(int position) {
    return position;
}

public View getView(final int position, View convertView, ViewGroup parent) {
    View view = convertView;

    if(convertView == null) 
        view = inflater.inflate(R.layout.hometile, parent, false);
    view.setId(position);
    TextView text=(TextView)vi.findViewById(R.id.tilecontent);;
    ImageView image=(ImageView)vi.findViewById(R.id.tileimage);

    if(position == 0)
    {
        text.setText("One");
    }
    else if(position == 1)
    {
        text.setText("Two");
    }
    else if(position == 2)
    {
        text.setText("Three");
    }
    else if(position == 3)
    {
        text.setText("Four");
    }
    else if(position == 4)
    {
        text.setText("Five");
    }
    else if(position == 5)
    {
        text.setText("Six");
    }


    imageLoader.DisplayImage(data[position], image);

    return view;
}
Community
  • 1
  • 1
user2960998
  • 17
  • 1
  • 6

1 Answers1

0

Are the images smaller than the grid tiles? If you need to scale them up then use one of these options

reactivemobile
  • 505
  • 3
  • 9
  • I don't think the images are smaller than the grid tiles. Although I did not set a size for the tiles the width matches the parent and the height wraps content. I have tried some considerably large images...the ones in use are 1500 width by 1000 height pixels – user2960998 Oct 21 '14 at 14:36
  • After reading the page you recommended, I set the centreCrop attribute on the imageview and it displays well now. Thank you for your help. – user2960998 Oct 21 '14 at 14:45