ImageView的和的LinearLayout中,ImageView的它越来越对图像的顶部和底部的空格 [英] ImageView and LinearLayout, the imageview it's getting blank spaces on top and bottom of the Image

查看:294
本文介绍了ImageView的和的LinearLayout中,ImageView的它越来越对图像的顶部和底部的空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Android上的一些问题的LinearLayout和ImageView的。我不能使用XML来定义布局,我试图了解与Java code做到这一点。

我对的LinearLayout两个元素,一个头(ImageView的)和主体(GridView控件与图像)。成才是走错了,因为ImageView的它变得顶部和原始图像的底部有些布兰克的空间。

这是我使用的标题不会对顶部和图像的底部这些空格原来ImageView的,我放线header.setBackgroundColor(Color.WHITE);然后我注意到,某些事正在错误的ImageView的,因为它让这些布兰克空间。

我有多个标题图片测试,我注意到,身高较高富人的形象,更大的是布兰克空间这样,他们dinamically某种错误/缺陷的

产生

如何删除它们?

下面是一个捕获:

下面是code:

 的LinearLayout LL =新的LinearLayout(本);
    ll.setOrientation(LinearLayout.VERTICAL);
    标题=新ImageView的(getApplicationContext());
    header.setImageResource(R.drawable.header_acc_old);
    header.setBackgroundColor(Color.WHITE);    myGridView =新的GridView(本);
    myImageAdapter =新ImageAdapter(本);
    myGridView.setAdapter(myImageAdapter);    ll.addView(头);
    ll.addView(myGridView);
    的setContentView(Ⅱ);

我trye​​d这些解决方案,但他们没有工作:

  ll.setLayoutParams(新LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT,LinearLayout.LayoutParams.WRAP_CONTENT));LinearLayout.LayoutParams的LayoutParams =新LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT,LinearLayout.LayoutParams.WRAP_CONTENT);
ll.addView(头,的LayoutParams);


解决方案

尝试使用 setBackgroundResource 而不是 setImageResource 而设置图像的ImageView。

I'm having some issues with LinearLayout and ImageView on Android. I must not use XML for defining the layouts, i'm trying to understand to do it with java code.

I have two elements on the linearLayout, a header (imageview) and a body (gridview with images). Someting is going wrong because the imageview it's getting some blanck spaces on top and on bottom of the original Image.

The original Imageview that i am using for the Header doesn't have these white spaces on top and on bottom of the image, i put the line header.setBackgroundColor(Color.WHITE); and then i noticed that something was going wrong with the imageview because its getting these blanck spaces.

I tested with multiple header images and i noticed that the higher height haves the image, the bigger are the blanck spaces so, they are generated dinamically for some kind of error/bug

How to remove them?

Here is a capture:

Here is the code:

LinearLayout ll = new LinearLayout(this);
    ll.setOrientation(LinearLayout.VERTICAL);
    header = new ImageView(getApplicationContext());
    header.setImageResource(R.drawable.header_acc_old);
    header.setBackgroundColor(Color.WHITE);

    myGridView = new GridView(this);
    myImageAdapter=new ImageAdapter(this);
    myGridView.setAdapter(myImageAdapter);

    ll.addView(header);
    ll.addView(myGridView);
    setContentView(ll);

I Tryed with these solutions, but they didn't work:

ll.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT));

LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
ll.addView(header,layoutParams);

解决方案

Try using setBackgroundResource instead of setImageResource while setting image to ImageView.

这篇关于ImageView的和的LinearLayout中,ImageView的它越来越对图像的顶部和底部的空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆