【发布时间】:2011-05-14 04:08:24
【问题描述】:
我有一个ImageView,我将它设置在xml 文件中基本页面的LinearLayout 的中心。我拍了一张照片,检测面孔并将其显示在我的ImageView 上。问题是,它总是显示在我手机的左侧(我将应用程序永久设置为portrait 模式)...我希望width 是fill_parent,我希望height 是已修复,但我所做的任何更改都不会影响它的显示方式。
这是我的xml 代码:
<ImageButton
android:id="@+id/YesButtonTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/yesface"
android:layout_gravity="top|center" />
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/image_view"
android:gravity="center"
android:layout_weight="1.0"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/message"
android:gravity="center_horizontal"
android:padding="10dip"/>
<Button
android:layout_gravity="center_horizontal"
android:layout_width="fill_parent"
android:textStyle="bold"
android:id="@+id/action_button"
android:selectAllOnFocus="false"
android:layout_height="100dip"
android:text="Click here to crop detected face"/>
在这里我将bitmap 设置为ImageView:
((Button) findViewById(R.id.action_button))
.setOnClickListener(btnClick);
mTheMessage.setText(R.string.faceMessage);
mThePicture = (ImageView) findViewById(R.id.image_view);
mThePicture.setImageBitmap(bitmap565);
bitmap565 定义为:
Bitmap bitmap565 = Bitmap.createBitmap(width, height, Config.RGB_565);
然后压缩:
try {
FileOutputStream fos = new FileOutputStream(filepath);
bitmap565.compress(CompressFormat.JPEG, 90, fos);
fos.flush();
fos.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
在我在ImageView 上显示bmp 之前。任何人都知道为什么它不会正常运行,ImageView 会正确吗?
【问题讨论】:
标签: android xml image layout imageview