2012-06-20 68 views
0

enter image description here擴大TextView的隱藏圖像

如上圖所示,這是我對他們幾個的一些複選標記的自定義列表視圖。基本上有兩個textview和一個imageview。我的問題是每當上方文本視圖中的文本很大時,圖像視圖就會脫離屏幕並且不顯示覆選標記。

我希望上層文本視圖的寬度應根據文本的長度進行擴展,但不應隱藏複選標記。

任何幫助欣賞。

編輯:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:padding="6dip" 
android:background="@color/black"> 
<ImageView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentTop="true" 
    android:layout_alignParentBottom="true" 
    android:layout_marginRight="6dip" 
    android:id="@+id/row_image"/> 
    <ImageView 
     android:id="@+id/multiselect_icon" 
     android:src="@drawable/singlecheck" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentTop="true" 
     android:layout_alignParentBottom="true" 
     android:layout_toRightOf="@id/row_image" 
     android:visibility="gone"/> 
     <TextView 
      android:id="@+id/top_view" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_toRightOf="@id/multiselect_icon" 
      android:layout_alignParentTop="false" 
      android:layout_alignParentRight="false" 
      android:textStyle="bold" 
          android:layout_weight="1" 
      android:textColor="@color/white"/> 
        <ImageView 
          android:id="@+id/shared_icon" 
          android:src="@drawable/sharedcheck" 
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content" 
          android:layout_toRightOf="@id/top_view" 
          android:visibility="gone"/> 
        <TextView 
      android:id="@+id/bottom_view_1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentBottom="false" 
      android:layout_alignParentLeft="false" 
      android:layout_below="@id/top_view" 
      android:layout_toRightOf="@id/multiselect_icon" 
          android:gravity="left" 
          android:textColor="@color/lightGray" 
          android:visibility="gone"/> 
     <TextView 
      android:id="@+id/bottom_view" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentBottom="true" 
      android:layout_alignParentRight="true" 
      android:layout_below="@id/top_view" 
      android:gravity="right" 
          android:textColor="@color/lightGray"/> 
</RelativeLayout> 

回答

1

想過分享答案,以便它可以幫助某人。

我將上面的文本框&複選標記添加到線性佈局&它解決了問題。

<LinearLayout 
    android:orientation="horizontal" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:id="@+id/upper_view" 
    android:layout_toRightOf="@id/multiselect_icon" 
    android:layout_alignParentTop="false" 
    android:layout_alignParentRight="false"> 

    <TextView 
     android:id="@+id/top_view" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textStyle="bold" 
    android:layout_weight="1" 
     android:textColor="@color/white"/> 
    <ImageView 
    android:id="@+id/shared_icon" 
    android:src="@drawable/sharedcheck" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_toRightOf="@id/top_view" 
    android:visibility="gone"/> 

</LinearLayout>   
+0

但是,這使共享檢查圖像保持對齊,不是嗎? – monchote

+0

@monchote是的,它的確如此。但至少它總是可見的。我嘗試使用權重來達到上面的效果,但是沒有通過。如果你能提供任何東西,我會很感激。 –

0

使用

android:layout_weight="1" 

在XML textview

+0

沒有工作.... –

+0

它不會在相對佈局 –

+0

那麼我應該怎麼辦???工作 –

0

如果您的ListView項目使用的是LinearLayout,我建議您將其替換爲RelativeLayout,然後將TextView對齊到選中標記的左側。

+0

我使用相對佈局只與左對齊的東西也。它不工作。 –