how to erase the empty space while the image is zero?

advertisements

I'm new to android domain.

My problem is.. I'm getting a empty space in the image view. From the database im retrieve the image as string and stored in array and displaying. When im getting null in the string that time i should not get a empty white space.

How to clear this? Any one help me.. Thanks a lot in advance...

I try like this...

        String pic = imgarr.get(g);
        System.out.println("picture:"+pic);
        if (pic != null && !pic.equals("")) {
            ImageView ImageView = (ImageView) findViewById(R.id.image);
            ImageView.setVisibility(View.GONE);
        }else{
        try {
              ImageView im = (ImageView)findViewById(R.id.image);
              Bitmap bitmap = BitmapFactory.decodeStream((InputStream)new URL("http://11.0.0.2/htss/kumar/image/"+pic).getContent());
              im.setImageBitmap(bitmap);
            } catch (MalformedURLException e) {
              e.printStackTrace();
            }
        }

XML

        <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
          xmlns:tools="http://schemas.android.com/tools"
           android:layout_width="fill_parent"
           android:layout_height="fill_parent"
            tools:context=".Quesans" >
        <ScrollView
android:layout_width="fill_parent"
android:layout_height="3500dip"
android:scrollbars="vertical"

 <RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
 <RadioGroup
 android:id="@+id/rdgroup"
 android:layout_width="fill_parent"
 android:layout_height="wrap_content"
 android:layout_alignParentLeft="true"
 android:layout_below="@+id/que_txt"
 android:layout_marginTop="300dp"
 android:orientation="vertical" >
 <RadioButton android:id="@+id/RB1" android:text=""/>
 <RadioButton android:id="@+id/RB2" android:text=""/>
 <RadioButton android:id="@+id/RB3" android:text=""/>
 <RadioButton android:id="@+id/RB4" android:text=""/>
</RadioGroup>
<ImageView
 android:id="@+id/nxt_btn"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_alignParentRight="true"
 android:layout_below="@+id/rdtxt"
 android:layout_marginRight="22dp"
 android:layout_marginTop="30dp"
 android:src="@drawable/next_normal" />
<TextView
 android:id="@+id/rdtxt"
 android:layout_width="fill_parent"
 android:layout_height="wrap_content"
 android:layout_alignParentLeft="true"
 android:layout_below="@+id/rdgroup"
 android:layout_marginTop="17dp"
 android:text="Nothing is picked"
 android:textColor="#0000FF"/>
 <ImageView
 android:id="@+id/focusarea"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_alignRight="@+id/nxt_btn"
 android:layout_below="@+id/nxt_btn"
 android:layout_marginRight="1dp"
 android:layout_marginTop="10dp"
 android:src="@drawable/focus_normal" />
 <TextView
 android:id="@+id/que_txt"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_alignParentLeft="true"
 android:layout_alignParentTop="true"
 android:layout_marginLeft="10dp"
 android:layout_marginTop="25dp"
 android:text="TextView" />
 <ImageView
 android:id="@+id/app"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
  android:layout_alignParentLeft="true"
  android:layout_alignParentBottom="true"
   android:layout_marginLeft="140dp"
  android:layout_marginBottom="0dp"
 android:src="@drawable/newapps" />
<ImageView
 android:id="@+id/image"
 android:layout_width="fill_parent"
 android:layout_height="wrap_content"
 android:layout_alignLeft="@+id/que_txt"
 android:layout_below="@+id/que_txt"
 android:layout_marginTop="150dp" />
<TextView
 android:id="@+id/soltxt"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_alignLeft="@+id/prv_btn"
 android:layout_alignTop="@+id/focusarea"
 android:layout_marginLeft="23dp"
 android:text="" />
 <ImageView
 android:id="@+id/prv_btn"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_alignLeft="@+id/image"
 android:layout_alignTop="@+id/nxt_btn"
 android:src="@drawable/previous_normal" />
 </RelativeLayout>
 </ScrollView>
 </RelativeLayout>


Try this,

if(imgarr.get(g)!=null)
{
    String pic = imgarr.get(g).toString().trim();
    System.out.println("picture:"+pic);
ImageView imageView = (ImageView) findViewById(R.id.image);
        if (pic.equalsIgnoreCase(""))
        {
                    imageView .setVisibility(View.GONE);
                }else{
                try {
                      Bitmap bitmap = BitmapFactory.decodeStream((InputStream)new URL("http://10.0.2.2/moodle/practice/question/images/"+pic).getContent());
                      imageView.setImageBitmap(bitmap);
                    } catch (MalformedURLException e) {
                      e.printStackTrace();
                    }
                }
    }

Edited

<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
tools:context=".Quesans">
    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <TextView
             android:id="@+id/que_txt"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:layout_alignParentLeft="true"
             android:layout_alignParentTop="true"
             android:layout_marginLeft="10dp"
             android:layout_marginTop="25dp"
             android:text="TextView" />
        <ImageView
             android:id="@+id/image"
             android:layout_width="fill_parent"
             android:layout_height="wrap_content"
             android:layout_alignLeft="@+id/que_txt"
             android:layout_marginTop="15dp"
             android:layout_marginBottom="10dp"
             android:layout_below="@+id/que_txt"/>
         <RadioGroup
             android:id="@+id/rdgroup"
             android:layout_width="fill_parent"
             android:layout_height="wrap_content"
             android:layout_alignParentLeft="true"
             android:layout_below="@+id/image"
             android:orientation="vertical" >
         <RadioButton
             android:id="@+id/RB1"
             android:text=""/>
         <RadioButton
             android:id="@+id/RB2"
             android:text=""/>
         <RadioButton
             android:id="@+id/RB3"
             android:text=""/>
         <RadioButton
             android:id="@+id/RB4"
             android:text=""/>
        </RadioGroup>
        <TextView
             android:id="@+id/rdtxt"
             android:layout_width="fill_parent"
             android:layout_height="wrap_content"
             android:layout_alignParentLeft="true"
             android:layout_below="@+id/rdgroup"
             android:layout_marginTop="17dp"
             android:text="Nothing is picked"
             android:textColor="#0000FF"/>
        <ImageView
             android:id="@+id/nxt_btn"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:layout_alignParentRight="true"
             android:layout_below="@+id/rdtxt"
             android:layout_marginRight="22dp"
             android:layout_marginTop="30dp"
             android:src="@drawable/next_normal" />
         <ImageView
             android:id="@+id/focusarea"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:layout_alignRight="@+id/nxt_btn"
             android:layout_below="@+id/nxt_btn"
             android:layout_marginRight="1dp"
             android:layout_marginTop="10dp"
             android:src="@drawable/focus_normal" />
         <ImageView
             android:id="@+id/app"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:layout_alignParentLeft="true"
             android:layout_alignParentBottom="true"
             android:layout_marginLeft="140dp"
             android:layout_marginBottom="0dp"
             android:src="@drawable/newapps" />
        <TextView
             android:id="@+id/soltxt"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:layout_alignLeft="@+id/prv_btn"
             android:layout_alignTop="@+id/focusarea"
             android:layout_marginLeft="23dp"
             android:text="" />
         <ImageView
             android:id="@+id/prv_btn"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:layout_alignLeft="@+id/image"
             android:layout_alignTop="@+id/nxt_btn"
             android:src="@drawable/previous_normal" />
     </RelativeLayout>
 </ScrollView>