Drawables extracted from the wrong resource folder during rotation

Pull my hair here. Therefore, I work with an application with several types of drawings, and I have them in this structure:

res/ //Portrait resources drawable-mdpi/ drawable-hdpi/ drawable-xhdpi/ //Landscape resources drawable-land-mdpi/ drawable-land-hdpi/ drawable-land-xhdpi/ 

EDIT I also tried even putting portrait-highlighted drawings under drawable-port-mdpi , etc. with the same result.

And I have a custom View that I use to draw drawings at runtime. Here's an example, but I have a problem:

 public class CustomView extends FrameLayout { private ImageView mBackgroundView; public CustomView (Context context) { super(context); initialize(); } public CustomView (Context context, AttributeSet attrs) { super(context, attrs); initialize(); } public CustomView (Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); initialize(); } private void initialize () { mBackgroundView = new ImageView(getContext()); mBackgroundView.setImageResource(R.drawable.my_resource); addView(mBackgroundView, wrapContent()); } private LayoutParams wrapContent () { return new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); } } 

I would expect that when I turn to the landscape (and let me clarify first, I AM NOT handling configChanges in the manifest for this Activity ), and this View created, mBackgroundView should get drawable in drawable-land-xhdpi . Conversely, when I turn back, I should get drawable at drawable-xhdpi .

Now that is getting weird. I can confirm that the drawings are all there and found, because if I run the application in the landscape, I get the correct landscape with the ability to draw . However, during rotation, the landscape remains unchanged, and I do not get a portrait portrait. Conversely, if I run in a portrait, I am stuck with a portrait.

Is there some special case that I have to handle with the resources "or w70" or sometime when I capture them programmatically?

+4
source share
1 answer

So, I found out where the problem is, and I'm honestly not sure if this is my misunderstanding or error in Android. I did not think of adding this as part of the question (looking back, I would have to), but my drawable was a list of layers that could be drawn with two images stacked on top of each other (one shadow, one image above the shadow):

 <layer-list xmlns:android="http://schemas.android.com/apk/res/android> <item> <bitmap android:src="@drawable/shadow"/> </item> <item> <bitmap android:src="@drawable/image" android:gravity="top|center_horizontal"/> </item> </layer-list> 

It seems that this is only played out once (I assume it is reused for efficiency), but it never returns and reconstructs the list of layers with drawings for the new configuration.

I changed the use of two aligned ImageViews instead of a drop-down list of layers, and all is well.

+1
source

All Articles