2016-11-23 23 views
-6

enter image description here通過文字填滿所有的空間由左到右,如果沒有圖像從服務器返回

大家好,我希望有一個佈局如下圖所示那裏是在TextView的右側ImageView的身影。如果圖像不存在,我希望文本顯示在整個屏幕上,如圖所示,我怎樣才能得到它。 對不起,我想說的是,我有一個自定義列表視圖,我只有一個textView和ImageView在適配器中。如果圖像不存在的同一字段我希望textview從左到右,以取代圖像視圖也。

+0

嘗試使用相對佈局 – SaravInfern

+0

@Shree爲更好的UI我已提出建議,圖書館。 – Varma460

回答

1
<?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"> 
    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" 
     android:layout_gravity="right" 
     android:gravity="right"> 
     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:text="Some Random Text for example ..........................................." 
      android:gravity="left" 
      android:layout_weight="5"/> 
     <ImageView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="left" 
      android:src="@drawable/jayz" 
      android:layout_weight="1"/> 
    </LinearLayout> 
    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:text="Some Random text for example............................................."/> 

</LinearLayout> 

enter image description here

根據您的編輯。

將第一個textView的layout_width更改爲match_parent,就像我一樣。

從您的代碼調用imageView.setVisibility(View.GONE);後,每當您的imageview應該是空的。

您的佈局會是這樣`

enter image description here

+0

事實上,我已經在發佈這個問題之前做了這個。你沒有得到我的問題。我編輯了我的問題,請再看一遍。我現在清楚還是仍然困惑。 – Shree

+0

看到我的編輯@Shree。 –

相關問題