【问题标题】:Gallery Image not fitting the screen in android图库图像不适合android中的屏幕
【发布时间】:2014-07-16 15:50:06
【问题描述】:

我正在图库视图中显示一堆图像。

布局是,

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical" >
<Gallery
    android:id="@+id/gallery1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:spacing="10dip" >
</Gallery>

<ImageView
    android:id="@+id/imgfromWebUrl"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >
</ImageView>
</LinearLayout>

以及用于加载图像的自定义适配器,

public View getView(int arg0, View paramView, ViewGroup arg2) {
    Log.d("","custom Adapter5");
    View localView;
    if (paramView == null) {
        localView = mInflater.inflate(R.layout.property_image_adapter, null);
    } else {
        localView = paramView;
    }       
    ImageView imgfromWebUrl=(ImageView)localView.findViewById(R.id.imgfromWebUrl);          
    Log.d("", "pics[0]: "+pics);
    imgfromWebUrl.setImageBitmap(pics[arg0]);
    imgfromWebUrl.setScaleType(ImageView.ScaleType.FIT_XY);
    imgfromWebUrl.setBackgroundResource(defaultItemBackground);
    imgfromWebUrl.setLayoutParams(new Gallery.LayoutParams(200, 200));
    return imgfromWebUrl;
}

目前我的图片显示为,

我的图像适合屏幕的中心部分。但我希望图像适合全屏,比如这张图片

请帮帮我!! 任何帮助表示赞赏!

【问题讨论】:

  • 设置你的 layout_width="match_parent" .
  • 您要删除图像周围的空间还是要全视图显示图像?
  • @Rushabh Patel,无论高度如何,我都希望图像适合屏幕宽度!!
  • 那么你需要在你的imageview中使用这个属性android:scaleType="fitXY"
  • 我已经在适配器类中设置了scaleType!

标签: android imageview gallery


【解决方案1】:

使用这个属性android:scaleType="fitXY" Document for ImageView.ScaleType

【讨论】:

    【解决方案2】:

    问题:

    图像适合父级。但您的图库参数固定为 200。

    解决方案:

    请删除该行。

    imgfromWebUrl.setLayoutParams(new Gallery.LayoutParams(200, 200));
    

    并在 xml 中进行此更改:

    <Gallery
    android:id="@+id/gallery1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:spacing="10dip" >
    

    【讨论】:

    • 我删除了该行,但它导致了这个异常:java.lang.ClassCastException: android.widget.linearlayout$layoutparams
    • 请将您的imageviewgallery 放在单独的xml 中,然后在getview 方法中扩展imageview 的布局
    【解决方案3】:

    像这样配置布局参数:

    i.setLayoutParams( new
    Gallery.LayoutParams(WindowManager.LayoutParams.MATCH_PARENT,
    WindowManager.LayoutParams.MATCH_PARENT));
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-05
      • 2021-02-28
      • 2021-05-23
      • 2020-12-07
      相关资源
      最近更新 更多