imageview

Dynamically change SVG image color in android

倖福魔咒の 提交于 2019-11-30 09:10:16
I know that using third party library, it is possible to use SVG image in Android. Library like: svg-android The code to load SVG image is like below: public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Create a new ImageView ImageView imageView = new ImageView(this); // Set the background color to white imageView.setBackgroundColor(Color.WHITE); // Parse the SVG file from the resource SVG svg = SVGParser.getSVGFromResource(getResources(), R.raw.android); // Get a drawable from the parsed SVG and set it as the drawable for the ImageView imageView

BitmapFactory.decodeFile returns null even image exists

 ̄綄美尐妖づ 提交于 2019-11-30 08:58:09
问题 Saving the file: FileOutputStream fo = null; try { fo = this.openFileOutput("test.png", Context.MODE_WORLD_READABLE); } catch (FileNotFoundException e) { e.printStackTrace(); } bitmap.compress(CompressFormat.PNG, 100, fo) Loading the file: String fname = this.getFilesDir().getAbsolutePath()+"/test.png"; Bitmap bMap = BitmapFactory.decodeFile(fname); i.setImageBitmap(bMap); The last line gives a null pointer exception, why is BitmapFactory.decodeFile returning null? I can verify that the file

Transparent part of image in ImageView become black

隐身守侯 提交于 2019-11-30 08:24:41
I have problem when displaying image with transparency in Android KitKat (Nexus 7), it is OK in nexus 4 (KitKat) and other previous Android OS, here the image: and ImageView layout: <ImageView android:id="@+id/avatar" android:layout_width="35dp" android:layout_height="35dp" android:layout_gravity="center_vertical" android:layout_marginLeft="21dp" android:padding="3dp" android:src="@drawable/icon_button_profile_new" android:tag="@string/avatar" /> and here the screenshot when running on Nexus 7 (Android 4.4) also, I use Picasso for download & caching image from the URL. hakim After some trial:

Using an xml Layout for a Google Map Marker for Android

你说的曾经没有我的故事 提交于 2019-11-30 07:38:23
I want to use a layout and not a drawable for my marker I am using with Google Maps Api 2 for an Android app. Like this: Marker m = googleMap .addMarker(new MarkerOptions() .position(LOC) .snippet(user) .title(name) .icon(BitmapDescriptorFactory.fromResource(R.layout.map_marker))); However, it seems this is only designed for use from drawable folder. I simply what an image with a background where I can change colors based on marker type. This is the layout I want to use: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width

android imageview.setBackgroundResource() doesn't work

一世执手 提交于 2019-11-30 07:10:37
问题 I have an imageview that should be changed on click public class Settings extends Activity implements OnClickListener { private ImageView im1; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.settings); im1 = (ImageView) findViewById( R.id.imageView1 ); im1.setOnClickListener(this); } @Override public void onClick(View v) { // TODO Auto-generated method stub if (v == im1 ) { Log.d("test", "hey!"); v.setBackgroundResource(R

How do I prevent scaling in Android Imageview?

守給你的承諾、 提交于 2019-11-30 06:46:59
I have an image that is 480 pixels by 40 pixels. I would like to show this image in an ImageView without having it scale to fit. Ex: If my screen is only 320pixels wide I would like only 320pixels of the image to show on the screen, not have it cram itself into the ImageView (even if it means that the rest of the image gets cut off). Is there a way to prevent it from scaling to fit? EDIT: Also, I would like the left side of the image to line up with the left side of the device's screen. Thanks nhaarman Use ScaleType.CENTER , like this in XML: android:scaleType="center" This will "center the

Android add arrow image to spinner

北战南征 提交于 2019-11-30 06:45:59
问题 I have created a background drawable that I use for a spinner. I would like to now but an arrow image inside this background. I have tried things like android:drawableRight="arrowimage", but this does not seem to show anything. Does anyone know how I can include an image in my custom background for a spinner? 回答1: Create an XML in a drawable folder with any name for example spinner_bg.xml and add this following lines <?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http:/

How to set image in imageview in android?

隐身守侯 提交于 2019-11-30 06:41:00
I want to show an image in imageview so I made a folder - drawable in res and put my image there. Something like apple.png . Then I use this code: ImageView iv= (ImageView)findViewById(R.id.img_selected_image); String path = getApplication().getFilesDir().getAbsolutePath(); InputStream is = new FileInputStream(path + "/apple.png"); Drawable icon = new BitmapDrawable(is); Log.i("Fnord", "width="+icon.getIntrinsicWidth()+ " height="+icon.getIntrinsicHeight()); iv.setImageDrawable(icon); But when i run it, it said there isn't any image by apple.png name in data/data/package-name/files . I think i

How to show images in imageview in simple adapter?

早过忘川 提交于 2019-11-30 05:32:40
问题 I am getting data from JSON Array and I can show the text in textviews but having problems with showing the images. here's the main activity: public class test extends ListActivity { // url to make request private static String url = "http://test/json.php"; // JSON Node names private static final String CONTACTS = "contacts"; private static final String NAME = "name"; private static final String IMAGE = "image"; // contacts JSONArray JSONArray contacts = null; @Override public void onCreate

How to load an ImageView from a png file?

拥有回忆 提交于 2019-11-30 05:04:33
I take a picture with the camera using Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE ); startActivityForResult( intent, 22 ); When the activity completes, I write the bitmap picture out to a PNG file. java.io.FileOutputStream out = openFileOutput("myfile.png", Context.MODE_PRIVATE); bmp.compress(Bitmap.CompressFormat.PNG, 90, out); That goes OK, and I can see the file is created in my app private data space. I'm having difficulty when I later want to display that image using an ImageView. Can anyone suggest code to do this? If I try to create a File with path