2017-08-04 14 views
0

我有一個ListView包含ImageView,TextView和複選框,但是, 當textView很長時,checkBox幾乎不可用。我想要ListView來適應一條線。我如何才能Listview適合?

如何解決我在圖像中提到的問題?

ROW

<LinearLayout 

    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentEnd="true" 
    android:layout_alignParentStart="true" 
    android:layout_alignParentTop="true" 
    android:padding="0dp" 
    android:weightSum="100" > 

    <ImageView 
     android:id="@+id/newImage" 
     android:layout_width="88dp" 
     android:layout_height="match_parent" 
     android:layout_weight="0.25" 
     android:clickable="false" 
     android:hapticFeedbackEnabled="false" 
     android:saveEnabled="false" /> 

    <TextView 

     android:id="@+id/newTaskTitle" 
     android:layout_width="wrap_content" 
     android:layout_height="63dp" 
     android:layout_alignParentTop="true" 
     android:layout_marginStart="11dp" 
     android:gravity="center_vertical" 
     android:text="Example" 
     android:textSize="20sp" 
     android:layout_weight="78.57" /> 

    <CheckBox 

     android:id="@+id/checkBox" 
     android:layout_width="51dp" 
     android:layout_height="match_parent" 
     android:layout_weight="18.45" 
     android:gravity="left|center" 
     android:text="@string/checkBox" /> 

</LinearLayout> 
</RelativeLayout> 

LISTVIEW

<ListView 
    android:id="@+id/listView" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_marginTop="203dp" 
    android:layout_alignParentTop="true" 
    android:layout_alignParentStart="true" /> 

<android.support.v7.widget.Toolbar 
    android:id="@+id/toolbar" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentStart="true" 
    android:layout_alignParentTop="true" 
    android:background="@android:color/transparent" 
    android:elevation="0dp" 
    android:minHeight="?attr/actionBarSize" 
    android:theme="?attr/actionBarTheme" /> 

LISTVIEW TO FIT PROBLEM (image)

回答

1

Imageview寬度已經被定義,因此,我們應該處理2次和一個始終應正確,中間文字要靈活o我們可以給予textview重量,它會正常工作。

你可以試試這個,

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"> 
    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentTop="true"> 

     <ImageView 
      android:id="@+id/newImage" 
      android:layout_width="88dp" 
      android:layout_height="match_parent" 
      android:clickable="false" 
      android:hapticFeedbackEnabled="false" 
      android:saveEnabled="false"/> 

     <TextView 

      android:id="@+id/newTaskTitle" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_alignParentTop="true" 
      android:layout_weight="1" 
      android:gravity="center_vertical" 
      android:text="sdfsdfs" 
      android:textSize="20sp"/> 

     <CheckBox 

      android:id="@+id/checkBox" 
      android:layout_width="wrap_content" 
      android:layout_height="match_parent" 
      android:gravity="left|center" 
      android:text="checkBox"/> 

    </LinearLayout> 
</RelativeLayout> 
+0

謝謝你,但複選框應該總是行的末尾。 textview可以很短或很長,但checbox應該在最右邊。如果我這樣做,複選框與Textview連接。 –

+0

好吧,我更新我的答案採取最新的XML和檢查。 –

+0

Okey它的作品謝謝你! –