2016-03-08 204 views
0

在我的片段活动中,我有一些页面有图像,有些没有。布局是这样的:Textview-Imageview-Textview,所以当我没有图像时,我希望Textviews低于彼此。这是我的XML:imageview和textview之间的巨大差距

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="#006400"> 

    <ScrollView 
     android:layout_width="fill_parent" 
     android:layout_height="match_parent"> 
     <RelativeLayout 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent"> 
    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="New Text" 
     android:id="@+id/handling" 
     android:textColor="#ffffff" 
     android:textSize="20dp" /> 

    <ImageView 
     android:layout_width="match_parent" 
     android:layout_height="200dp" 
     android:id="@+id/stilling" 
     android:layout_below="@id/handling" 
     android:layout_gravity="center_vertical" /> 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:textAlignment="center" 
       android:text="New Text" 
       android:id="@+id/arabisk" 
       android:layout_below="@id/stilling" 
       android:layout_gravity="center" 
       android:textSize="18dp" 
       android:textColor="#ff0000" /> 

     </RelativeLayout> 

    </ScrollView> 

</LinearLayout> 

This is what I get

编辑:

我的图片

int[] billede = new int[18]; 
     billede[1] = R.mipmap.sojle1; 
     billede[2] = R.mipmap.sojle4; 
     billede[3] = R.mipmap.sojle2; 
     billede[4] = R.mipmap.sojle3; 
     billede[6] = R.mipmap.sojle4; 
     billede[8] = R.mipmap.sojle6; 
     billede[10] = R.mipmap.sojle7; 
     billede[12] = R.mipmap.sojle8; 
     billede[15] = R.mipmap.sojle9; 

     stilling.setImageResource(billede[mPage]); 

     return view; 
+3

以及您设置的高度为ImageView的所以你能指望什么。如果没有图像设置'GONE'的可见性 – tyczj

+0

我该如何在我的阵列中做到这一点? (已上传)我不能写'比勒德[13] = stilling.GONE' – Hudhud

+0

你设置imageview不去位图 – tyczj

回答

1

设置可视性,以GONE

在XML

android:visibility="GONE" 

或通过代码

imageView.setVisibility(View.GONE); 
+0

但是现在它根本不显示任何图像 – Hudhud

+1

@Hudhud因为它消失了吗?如果您通过代码设置src,则必须再次将可见性设置为“View.VISIBLE”。 –

+0

如何做到这一点?我不能说'if(billede [mPage]!= null)stilling.setVisibility(View.VISIBLE); stilling.setImageResource(billede [MPAGE]); }'作为运算符'!='不能应用于null/int – Hudhud

0

设置ImageView的知名度,走了,你的文本视图的数组必须是一个低于其他像你想。像这样

stilling.setVisibility(View.GONE); 
0

使用LinearLayout而不是RelativeLayout。并设置可见的View.GONE来隐藏ImageView