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