【问题标题】:I cannot for the life of me figure out why my picture is not displaying correctly我一生都无法弄清楚为什么我的图片显示不正确
【发布时间】:2011-05-14 04:08:24
【问题描述】:

我有一个ImageView,我将它设置在xml 文件中基本页面的LinearLayout 的中心。我拍了一张照片,检测面孔并将其显示在我的ImageView 上。问题是,它总是显示在我手机的左侧(我将应用程序永久设置为portrait 模式)...我希望widthfill_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


    【解决方案1】:

    这对我有用,也许对你也有用。

     <ImageView
        android:id="@+id/image_id"
        android:padding="2dip"
        android:layout_width="fill_parent" 
         android:layout_height="wrap_content"
         android:scaleType="centerInside"
         android:layout_weight="1"/>
    

    至于为什么你的 xml 不起作用。我看了看,一切似乎都很好,除了 android:gravity 在图像的情况下似乎什么都不做。

    【讨论】:

    • 还是一样的结果...我似乎可以对 xml 文件做任何我想做的事情,它仍然以相同的方式显示 - 我在课堂上做错了吗?
    • 我会做一个消除过程。取出 XML 的所有其他内容,看看它的外观。使用它直到它显示为您想要的,然后添加其他小部件。
    【解决方案2】:

    设置 layout_width="wrap_content" 不是 fill_parent,那么只有你会得到父 Layout 重力的影响

    <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/image_view"
            android:gravity="center"
            android:layout_weight="1.0"/>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-01-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-04
      • 1970-01-01
      • 2015-04-23
      相关资源
      最近更新 更多