2015-02-10 14 views
0

這是一個ListView我的自定義項目:列表視圖自定義項控制對準

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:descendantFocusability="blocksDescendants" 
    android:orientation="horizontal"> 
<RelativeLayout 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"> 
    <ImageView 
     android:id="@+id/listicon_imageview" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentTop="true" 
     android:layout_marginTop="10dp" 
     android:layout_marginBottom="10dp" 
     android:layout_marginLeft="10dp" 
     android:scaleType="centerInside" 
     android:src="@drawable/ic_launcher" /> 

    <TextView 
     android:id="@+id/textView1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="20dp" 
     android:layout_marginTop="10dp" 
     android:layout_toRightOf="@+id/listicon_imageview" 
     android:text="This is my long text that should wrap appropriately and not overlay controls" 
     android:ellipsize="end" 
     android:singleLine="true" 
     android:textSize="16sp" /> 

    <TextView 
     android:id="@+id/textView2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignBottom="@+id/listicon_imageview" 
     android:layout_alignLeft="@+id/textView1" 
     android:ellipsize="end" 
     android:singleLine="true" 
     android:text="Description" /> 

    <CheckBox 
     android:id="@+id/check_favorite_list" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="right" 
     android:layout_alignBaseline="@+id/textView1" 
     android:layout_alignBottom="@+id/textView1" 
     android:layout_alignParentRight="true" 
     android:layout_marginRight="20dp" 
     android:enabled="false" 
     android:focusable="false" 
     android:button="@android:drawable/btn_star"/> 

    <CheckBox 
     android:id="@+id/check_offered_list" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignBaseline="@+id/textView2" 
     android:layout_alignBottom="@+id/textView2" 
     android:layout_alignParentRight="true" 
     android:focusable="false" 
     android:enabled="true" 
     android:layout_marginRight="20dp" /> 

</RelativeLayout> 

</LinearLayout> 

該代碼會產生這個列表項:

enter image description here

人們可以看到,小文覆蓋複選框控件。不過,我希望textview2在複選框之前顯示橢圓點,以便複選框不會像這樣重疊。如何才能做到這一點?謝謝!

+0

你可以註釋掉'android:ellipsise'並重試嗎? – 2015-02-10 10:03:27

+0

在textview2中使用'leftof「check_offered_list」,希望能解決你的問題。 – prakash 2015-02-10 10:05:53

回答

0

你應該把android:layout_toLeftOf="@+id/check_favorite_list"放在TextView2中。該語句將textview2與checkBox的左側對齊(不覆蓋)。

希望它可以幫助你!

+1

非常好。這就馬上做到了!謝謝。 – 2015-02-10 10:18:35

+0

其他文字視圖呢? – 2015-02-10 10:20:43

-1

使用這個。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:paddingStart="16dp" 
android:paddingEnd="16dp" 
android:orientation="horizontal"> 

<ImageView 
    android:layout_width="64dp" 
    android:layout_height="64dp" 
    android:src="@drawable/ic_launcher" /> 

<LinearLayout 
    android:layout_width="0dp" 
    android:layout_weight="1" 
    android:layout_height="wrap_content" 
    android:padding="8dp" 
    android:orientation="vertical"> 

    <TextView 
     android:id="@+id/textView2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:ellipsize="end" 
     android:singleLine="true" 
     android:textSize="18sp" 
     android:text="Speisopfer (10.02.2014)" /> 

    <TextView 
     android:id="@+id/textView1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="4dp" 
     android:text="This is my long text that should wrap appropriately and not overlay controls. sdfsd dsf sdfds ds " 
     android:ellipsize="end" 
     android:maxLines="2" 
     android:textSize="16sp" /> 
</LinearLayout> 

<LinearLayout 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:orientation="vertical"> 

    <CheckBox 
     android:id="@+id/check_favorite_list" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:enabled="false" 
     android:focusable="false" 
     android:button="@android:drawable/btn_star" /> 

    <CheckBox 
     android:id="@+id/check_offered_list" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:focusable="false" 
     android:enabled="true" /> 
</LinearLayout> 

希望能,這將解決您的問題。