开发者

ImageView and LinearLayout, the imageview it's getting blank spaces on top and bottom of the Image

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?

开发者_如何学JAVA

Here is a capture:

ImageView and LinearLayout, the imageview it's getting blank spaces on top and bottom of the Image

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜