Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/229.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何在图像为空时清除空空间?_Android_Imageview - Fatal编程技术网

Android 如何在图像为空时清除空空间?

Android 如何在图像为空时清除空空间?,android,imageview,Android,Imageview,我是android域名的新手 我的问题是。。 我在图像视图中得到一个空白。从数据库im检索字符串形式的图像并存储在数组中并显示。当我在字符串中得到null时,我不应该得到一个空白 如何澄清这一点?谁能帮帮我。。 先谢谢你 我试着这样 XML 只需卸下盖子!从您的代码中 if (pic == null && pic.equals("")) { 试试这个 if(imgarr.get(g)!=null) { String pic = imgarr.get(g).toStri

我是android域名的新手

我的问题是。。 我在图像视图中得到一个空白。从数据库im检索字符串形式的图像并存储在数组中并显示。当我在字符串中得到null时,我不应该得到一个空白

如何澄清这一点?谁能帮帮我。。 先谢谢你

我试着这样

XML



只需卸下盖子!从您的代码中

if (pic == null && pic.equals("")) {
试试这个

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();
                    } 
                } 
    }
已编辑

<?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>


您能展示一下您的布局吗,停用?是否显示空白?当pic为空时,如何检查空链接?我仍然获得空白,你在哪里获得空白?在我的xml id中,que_txt代表问题,无线电组代表答案,id图像代表问题的图像视图,我在这里获得空白..请帮助我我犯了什么错误你看到我的屏幕截图变白了吗空格检查if-else条件下的执行流,执行什么(if/else)?更改答案中的url
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();
                    } 
                } 
    }
<?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>