Reputation: 578
I want to arrange border for my image view for my retrieved imaged from sd card and displayed in grid view.My default application looks like images without border like this
But i want to modify it for the screen which should be look like this included images with border
please give me solution for it.I have posted th code for my ImageAdapter.java
import java.util.ArrayList;
public class ImageAdapter extends BaseAdapter
{
public static ArrayList<Images> array=new ArrayList<Images>();
Context mContext;
private LayoutInflater mInflater;
public ImageAdapter(Context c,ArrayList<Images> arr)
{
mContext = c;
array=arr;
mInflater = LayoutInflater.from(mContext);
Log.e("","adapter con");
}
public int getCount()
{
Log.e("Count",""+array.size());
return array.size();
}
public Object getItem(int index)
{
// return 0;
return array.get(index);
}
public long getItemId(int index)
{
return index;
}
public View getView(int position, View convertView, ViewGroup parent) {
GridView.LayoutParams layoutParams = new GridView.LayoutParams(80, 80);
ImageView imageView = new ImageView(mContext);
Images i=array.get(position);
imageView.setImageBitmap(i.getBitmap());
imageView.setScaleType(ImageView.ScaleType.FIT_XY);
imageView.animate();
return imageView;
}
}
Thanks
Upvotes: 0
Views: 7834
Reputation: 54322
You can set a background in your xml and set padding to your ImageView initially. And later, just call setBackground which will set the background in the way you want.
<ImageView android:id="@+id/user_image"
android:layout_width="75dip"
android:layout_height="75dip"
android:padding="2dip"
android:background="ffffff"/>
or
image.setPadding(2, 2, 2, 2);
image.setBackgroundColor(Color.WHITE);
then
Set Scale Type like this,
image.setScaleType(ScaleType.FIT_XY);
image.setBackgroundResource(R.drawable.icon);
Upvotes: 2
Reputation: 15701
can try .. setBackgroundResource of image view with padding 2dp ........ make look like same.......
or
as per link found below a more standard way
view_default.xml
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#FFFFFF" />
<stroke android:width="1dp" android:color="#000000" />
<padding android:left="1dp" android:top="1dp" android:right="1dp"
android:bottom="1dp" />
</shape>
and refer this as well for set border to imageview dynamically
v.setBackgroundResource(R.drawable.view_default);
Upvotes: 4