I'm now trying to make a ListView with a fast scroll on it.
And I made a custom fast scroll thumb with the code following:
try {
Field f = AbsListView.class.getDeclaredField("mFastScroller");
f.setAccessible(true);
Object o = f.get(listview);
f = f.getType().getDeclaredField("mThumbImage");
f.setAccessible(true);
ImageView iv = (ImageView) f.get(o);
iv.setImageDrawable(drawable);
// Drawable drawable = (Drawable) f.get(o);
// drawable =
// getResources().getDrawable(R.drawable.scroll_selector);
// f.set(o, drawable);
return true;
} catch (Exception e) {
e.printStackTrace();
}
return false;
Although it shows image perfectly, it has an invisible area that occupies too much part of ListView row. Can anyone give me a suggestion what I should do right now? I want the scroll to be placed at the end of the right edge..
Related
I'm using AndroidSVG to dynamically place a signature rendered as an svg, for displaying to an ImageView.
Here is my code:
SVG svg = SVG.getFromString(singleEmployee.signature);
ImageView image_view = (ImageView) layout_signature.findViewById(R.id.toolboxtalk_signature_svg);
image_view.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
image_view.setTag(String.format(Locale.US, "employee_signature%d", x));
Drawable drawable = new PictureDrawable(svg.renderToPicture());
image_view.setImageDrawable(drawable);
My question is, how do I get the SVG out of the ImageView later in my code execution.
Here is what I'm trying:
ViewGroup v1 = (ViewGroup) findViewById(R.id.job_ticket_form);
ImageView signatureImageView = (ImageView) v1.findViewWithTag("employee_signature1");
PictureDrawable pictureDrawable = (PictureDrawable) signatureImageView.getDrawable();
Picture picture = pictureDrawable.getPicture();
Context context = signatureImageView.getContext();
String employeeSigSVGString = null;
try {
SVG svg = SVG.getFromResource(signatureImageView.getContext(), R.id.toolboxtalk_signature_svg);
employeeSigSVGString = spinner_value + "|" + svg;
} catch (SVGParseException e) {
e.printStackTrace();
}
Any ideas how to get the SVG back out of the ImageView?
So i am creating my views programatically like so:
for (int i = 0; i < num_devices; i++) {
ImageView imageView = new ImageView(this);
LinearLayout.LayoutParams vp = new LinearLayout.
LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
imageView.setLayoutParams(vp);
try {
Class res = R.drawable.class;
Field field = res.getField(device_types.get(i));
int resId = field.getInt(null);
imageView.setImageResource(resId);
}
catch (Exception e) {
Log.e("MyTag", "Failure to get drawable id.", e);
}
LinearLayout link_devices = (LinearLayout) findViewById(R.id.link_devices);
link_devices.addView(imageView);
}
And i am trying to get the coordinates of the imageview:
I have tried the following methods, but am getting no where
imageView.getDrawable().getBounds().centerX() /centreY
imageView.getX() / getY
imageView.getLocationInWindow(); / onScreen();
Could someone please explain to me how to get the cooridinates of the image which is a drawable so i can draw a box around it or draw lines between two images (that is the planned functionality)
int top = imageView.getTop();
int left = imageView.getLeft();
From there you have the top-left point coordinates.
I have the problem: when you try to add ImageView the LinearLayout, some images are not loaded and the program stops with a black screen. Picture JPG or PNG there is no difference. Tried to change the size of 100x100px to 1080x1920. If I replace the picture on another then everything is fine, but I need this picture. I put the exception to this code, but in the logcat nothing, i.e. the exception does not occur.
Please help me. Thank you.
for (int i = 0, lenI = anims.length; i < lenI; i++ ) {
try {
LinearLayout linearLayout = new LinearLayout(this);
linearLayout.setOrientation(LinearLayout.HORIZONTAL);
//add image
ImageView imageView = new ImageView(this);
linearLayout.addView(imageView);
int resId = getResources().getIdentifier("ru.romston.testprog:drawable/"+pics[i], null, null);
imageView.setImageResource(resId);
imageView.setMaxHeight(100);
imageView.setMaxWidth(100);
imageView.setPadding(5,5,5,5);
imageView.setAdjustViewBounds(true);
//label
TextView textView = new TextView(this);
linearLayout.addView(textView);
textView.setText(anims[i]);
layout.addView(linearLayout);
} catch (Exception e) {
Log.e(TAG, "read data: error!" + e.getMessage(), e);
}
}
I think the image is of higher resolution/size that Android rendering system fails to scale it into height and width of 100. Try with same image after changing the image size/resolution.
Please correct if wrong.
ImageViews have a resolution limit based on OpenGL. If the bitmap or image passes this limit resolution, it shows a black screen and throws no error.
You can retrieve this limit by querying OpenGL:
int[] maxSize = new int[1];
GLES10.glGetIntegerv(GL10.GL_MAX_TEXTURE_SIZE, maxSize, 0);
See this answer for more details
Hi I am trying to programatically add an image to an activity for an android app
I have this :
for (int i = 0; i < num_devices; i++) {
ImageView imageView = new ImageView(this);
LinearLayout.LayoutParams vp = new LinearLayout.LayoutParams
(ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
imageView.setLayoutParams(vp);
try {
Class res = R.drawable.class;
Field field = res.getField(device_types.get(i));
int resId = field.getInt(null);
imageView = (ImageView) findViewById(resId);
}
catch (Exception e) {
Log.e("MyTag", "Failure to get drawable id.", e);
}
LinearLayout link_devices = (LinearLayout) findViewById(R.id.link_devices);
link_devices.addView(imageView);
however it doesnt let me get the location of the images ( i try and get 0 for getTop, getLeft etc..)
am i doing it wrong and was is the correct way to do it
You are not setting image on that imageview, and you have set WRAP_CONTENT as layout params, which means the size of the imageView is same as size of image you are setting on it.
Since no image is attached the imageView size is 0.
Try setting an image, using any one of the codes ;- imageView.setImageBitmap(Bitmap bm), setImageDrawable(Drawable drawable) or setImageResource(int ResID).
I don't get what you're doing the with this code & its not required:
Class res = R.drawable.class;
Field field = res.getField(device_types.get(i));
int resId = field.getInt(null);
imageView = (ImageView) findViewById(resId);
I believe this is pretty trivial but I can't get it to work.
I want to display a default image in gallery elements (ImageViews) while their actual image is being fetched from the net.
Right now, nothing is shown for an ImageView which its image has yet to arrive. Once it arrives it is immediately shown.
What I tried is right after the instantiation of the ImageView to call its setImageResource function like so:
final ImageView i = new ImageView(mContext);
i.setImageResource(R.drawable.loading);
But it doesn't seem to work. Below is the full getView() function.
Any help is appreciated.
Thanks.
public View getView(int position, View convertView, ViewGroup parent) {
final ImageView i = new ImageView(mContext);
i.setImageResource(R.drawable.loading);
// if the drawbale is in the buffer - fetch it from there
Drawable bufferedImage = DataManager.getInstance().getImagesBuffer()[position];
if (bufferedImage != null){
i.setImageDrawable(bufferedImage);
BitmapDrawable drawable = (BitmapDrawable) i.getDrawable();
drawable.setAntiAlias(true);
}
// if drawable is not in buffer - fetch it from the net via AsyncImageLoader
else
{
String imageUrl = DataManager.getInstance().getImageBufferInstance().getImageUrl(position);
Drawable downloadedImage = AsyncImageLoader.getInstance().loadDrawable(imageUrl, new ImageCallback() {
public void imageLoaded(Drawable imageDrawable, String imageUrl) {
if (imageDrawable == null)
{
imageDrawable = getResources().getDrawable(R.drawable.icon);
}
i.setImageDrawable(imageDrawable);
BitmapDrawable drawable = (BitmapDrawable) i.getDrawable();
drawable.setAntiAlias(true);
}
});
i.setImageDrawable(downloadedImage);
}
i.setLayoutParams(new CoverFlow.LayoutParams(Utils.getInstance().getScreenWidth() / 2,
Utils.getInstance().getScreenHeight() / 2));
i.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
return i;
}
Fix your indentation... If I'm reading that correctly, you're only setting the temporary drawable icon in the imageLoaded callback of your (not shown) AsyncImageLoader, which I assume means it's then only being set after the image downloads and is then immediately overwritten with the downloaded image. Try moving the placeholder-setting code into your else block outside the callback.