开发者

Why is my image disappearing in landscape mode?

I have an image in portrait mode, which is displayed correctly. When I change the configuration to landscape, the image is not displayed.

Note that the LinearLayout, enclos开发者_如何学Pythoning the ImageView is displayed right(I checked it by changing the background). But when I changed the background for the ImageView, the background was also not shown.

   <LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:padding="10dp" android:layout_weight="3">
           <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center_vertical" android:minHeight="48dp" android:minWidth="48dp" android:src="@drawable/xyz" android:id="@+id/img"/>


Do you have different files specified for portrait and landscape more? I.e., do you have a layout file with the same name in the layout folder as well as the layout-land folder? If so, make sure both files include the ImageView.


You are most likely specifying the file you want to display like

myImageView.setImage("myfile.jpg");

in your onCreate method.

Move this code to onResume (create onResume with the @Override if you do not already have it) This will fix your problem


OK, your layout file is unnecessarily large and complex. So let's try a couple of things-

First, try creating a simple version of your XML file that contains the barebones for displaying the image. If that works in both portrait and landscape, you know that the problem is not your activity or your image.

If the first step works, the next step would be to work on simplifying your layout file, there is a lot that could be pruned. It goes seven layers deep at points, that should almost never happen. Here is a good blog post by an Android engineer on better layout design. You can find similar resources elsewhere.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜