drawable

How to get list of image with R.Drawable

风格不统一 提交于 2019-12-24 18:27:26
问题 In order to create a tile management system I have a pack of image in my res/drawable directory. How to load that ressource dynamically ? like : F_16.0_0_112.jpg. ("F_"+zoom"+"._"+XCoord+"_"+YCoord".jpg") Is there a fonction like getDrawable(String) ? 回答1: You can get a drawable using its name by: int id = getResources().getIdentifier("name_of_resource", "id", getPackageName()); 回答2: You can get this using reflection (dont forget to import java.lang.reflect.Field) /** * For example calling

How to set ImageView drawable Size based on Its parent view size?

Deadly 提交于 2019-12-24 08:34:44
问题 I have imageView inside a relative layout. And when i create the activity i run thread to grap bitmap from the internet and set the imageView. What i want is to resize the bitmap to scale based on relative view size while keeping the aspect ratio. The code for resizing the image is working but what i do is i get the relative view size by calling myRelativeView.getWidth() & myRelativeView.getHeight() and i feel that i should not do that because the docs say it could return 0. So what is the

Why do resolutions become smaller after a image file be read by program?

早过忘川 提交于 2019-12-24 06:47:49
问题 I meet a problem: I have images file having different sizes. (hdpi, xhdpi, xxhdpi, xxxhdpi) When I used the image files in the in the hdpi,xhdpi,xxhdpi devices, it's good. But when the device is xxxhdpi, the resolutions of the image files was became smaller. I don't know why it had happened. For example: I have 2 devices, one's resolution is xxhdpi, another one is xxxhdpi. And I have 2 image files, one is put in the folder "drawable-xxhdpi", it's resolution is 1080x1920. Another one is put in

How to check image resource of an imageview programmatically?

风流意气都作罢 提交于 2019-12-24 05:04:10
问题 I want to check background of my imageview and do sth if it equals to some drawable in my drawable folder. How can I do that? I have try this code but no answer: layoutRoot.setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { if (view.getBackground() == R.drawable.grid_single_bg_selected) { //Do sth } } }); 回答1: When you set the background drawable also do set a tag to the imageview imageView.setTag(R.drawable.demo); And then compare if (((Integer) imageView

Using NinePatch (.9.png) for making scaled Bitmaps

此生再无相见时 提交于 2019-12-24 04:44:30
问题 I need to draw a Bitmap for my new Android Application. Since my content view is set to a Game-Panel class I've created. I want to display images through Bitmap. Just because its more convenient, and easier to do then anything else. From what I've gathered from researching, Nine Patch images (.9.png) are used in android to scale more properly then regular Drawable images. It also says "This can be used for scaling properly in backgrounds. For example a regular button background...". If Nine

Is it possible to access a drawable from a specific density in Android?

廉价感情. 提交于 2019-12-24 03:07:46
问题 Depending on the situation of course, I normally have a drawable for each density my app supports and the right density drawable is used when I use an id reference of some drawable. But I'm looking to access a drawable from a specific density (for example, ldpi) no matter the density running on the device. But I want this on a specific situation, not everywhere, that would defeat the purpose of having multiple drawables for each density. Is this possible? 回答1: I dont know that it is possible

How put the logo of toolbar at right?

血红的双手。 提交于 2019-12-24 00:33:12
问题 I did this to "inflate" the logo at the toolbar: toolbar.setNavigationIcon(R.drawable.navigationIcon); toolbar.getNavigationIcon().setTint(Color.BLUE); toolbar.setLogo(R.drawable.logo); toolbar.getLogo().methodForFloatRightHere(); Does there exist some simple method that doesn't use "inflate" on a view? 回答1: You can add custom views to a toolbar. The key is the android:layout_gravity="center" on the logo ImageView . <android.support.v7.widget.Toolbar android:id="@+id/toolbar" android:layout

Programmatically add Gradient with solid color and stroke

前提是你 提交于 2019-12-23 19:15:07
问题 Currently I am using this code to add color: ShapeDrawable drawable = new ShapeDrawable(new OvalShape()); drawable.getPaint().setColor(color); Now I need to apply some gradient colors to it along with stroke(like border with different color). I am setting this as background to button. Here is what I am expecting, I need to do it programmatically. 回答1: Add a RadialGradient to your drawable like this: Shader shader = new RadialGradient(x, y, radius, color0, color1, Shader.TileMode.REPEAT);

Programmatically change button background drawable onClick

╄→尐↘猪︶ㄣ 提交于 2019-12-23 07:29:28
问题 I am trying to toggle my button's background drawables, so that when the user clicks the button its background is changed and when the user clicks the button again its background returns to defaul. Here is my code: public void Favorites(View V) { Button star = (Button) findViewById(R.id.buttonStar); if(star.getBackground().equals(R.drawable.btn_star_off)) { star.setBackgroundResource(R.drawable.btn_star_on); } else { star.setBackgroundResource(R.drawable.btn_star_off); } } I am pretty sure

Create drawable from bitmap

∥☆過路亽.° 提交于 2019-12-23 07:03:15
问题 ALL, As suggested here I need to make a drawable out of my bitmap. But when I tried to use: Drawable d = new Drawable( my_bmp); it shows that this constructor is deprecated in favour of: Drawable(Bitmap bmp, int resourceId) How else I can make a drawable out of bitmap? Thank you. 回答1: You can use Drawable d = new BitmapDrawable(getResources(), my_bmp); A Drawable that wraps a bitmap and can be tiled, stretched, or aligned. You can create a BitmapDrawable from a file path, an input stream,