在Galaxy Tab 2上加载图像时的布局问题
问题描述:
将大于Galaxy Tab 2 P5100(运行4.1.2)宽度的图像加载到ImageView中会为加载的图像添加某种顶部/底部填充。在Galaxy Tab 2上加载图像时的布局问题
下面是与Show layout boundaries
截图开启:
下面是它应该如何看(从Nexus 10的运行4.4.2):
我使用的代码(对于上述两个示例)是
public class ImageBugActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_bug);
// This bug is still reproducible if I use the
// Universal-Image-Loader library or if I change the dimensions of
// the image to a different width
loadImage("http://placehold.it/1600x1000", (ImageView)findViewById(R.id.image));
}
private void loadImage(final String url, final ImageView view) {
new Thread(new Runnable() {
@Override
public void run() {
try {
final Bitmap bitmap = BitmapFactory.decodeStream(new URL(url).openConnection().getInputStream());
runOnUiThread(new Runnable() {
@Override
public void run() {
view.setImageBitmap(bitmap);
}
});
} catch (Exception e) {
Log.e("loadImage", e.getMessage(), e);
}
}
}).start();
}
}
而且布局文件是
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="On a Galaxy Tab 2 the image below it is pushed to the center of the remaining space." />
<ImageView
android:id="@+id/image"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="top" />
</LinearLayout>
这个问题似乎是一个Android /三星的错误还是我做出愚蠢的错误?
答
您应该使用ImageView的layout_height
的"match_parent"
。
<ImageView
android:id="@+id/image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="top" />
+0
这不起作用。请注意,我上面发布的代码在Nexus 10设备上完美工作。 – Nachi
尝试在系统设置 - >开发人员选项中将“显示布局边界”选项设置为true。然后打开应用程序并检查边界是 – Sam
@ SamN-a:谢谢!它似乎没有提出解决方案,但我更新了屏幕截图。 – Nachi
尝试将布局更改为RelativeLayout。您必须添加一些其他修改,例如添加alignParentTop,layout_below,但它可能是值得的。目前我认为这是一个错误,因为这种行为是出乎意料的 – Sam