2015-09-28 6 views
0

Я собираюсь использовать CheckBox и TextView в виде списка. Я использую этот XML-код для выравнивания ListView пунктов:Как использовать флажок и текстовое представление в представлении списка вместе?

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal" > 
    <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" > 
     <CheckBox 
      android:id="@+id/checkBox1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" /> 
    </LinearLayout> 
    <TextView 
     android:id="@+id/textView_Item_Listview" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:padding="3dp" 
     android:text="gfhfgh" 
     android:textSize="25sp" /> 
</LinearLayout> 

Я хочу, чтобы выровнять TextView направо и налево CheckBox.

+1

Почему вы даже нужен 'TextView'? 'CheckBox' является расширением' TextView' и поддерживает, например, 'android: text'. Поскольку мы говорим в контексте «ListView», вы также можете проверить ['CheckedTextView'] (http://developer.android.com/reference/android/widget/CheckedTextView.html). –

+0

Я хочу использовать флажки для выбора и удаления listView Items – programmer138200

+0

Вы правы. Я не могу коснуться текстовых просмотров в виде списка сейчас – programmer138200

ответ

1
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal" 
    android:weightSum="5" > 

     <CheckBox 
      android:id="@+id/checkBox1" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1"/> 

    <TextView 
     android:id="@+id/textView_Item_Listview" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:padding="3dp" 
     android:text="gfhfgh" 
     android:layout_weight="4" 
     android:textSize="25sp" /> 
</LinearLayout> 
+0

спасибо. Я использую это и добавляю (android: gravity = "right") к текстовому коду. Он решен – programmer138200

+0

Добро пожаловать, круто это сработало для вас :) –

+0

Rajan KS: Я не могу трогать текст сейчас. Я могу прикоснуться к флажку и проверить его, но Onclicklistener не работает сейчас – programmer138200

1

Добавить TextView в LinearLayout как этот

<LinearLayout 
android:orientation="horizontal" 
android:layout_width="wrap_content" 
android:layout_height="match_parent" > 

<CheckBox 
    android:id="@+id/checkBox1" 
    android:weight="0.5" 
    android:layout_width="0dip" 
    android:layout_height="wrap_content" /> 


<TextView 
android:id="@+id/textView_Item_Listview" 
android:weight="0.5" 
android:layout_width="0dip" 
android:layout_height="wrap_content" 
android:padding="3dp" 
android:text="gfhfgh" 
android:textSize="25sp" /> 

</LinearLayout> 
1

Вам не нужно такой сложный макет. Checkbox отправляет все элементы, которые вам нужны. Вы можете использовать это:

<CheckBox 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:text="someText" 
    android:button="@null" 
    android:drawableLeft="@drawable/someDrawable"/> 
1

Вы можете использовать RelativeLayout для например

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal" > 

<CheckBox 
    android:id="@+id/checkBox1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:alignParentLeft="true"> 

<TextView 
    android:id="@+id/textView_Item_Listview" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:padding="3dp" 
    android:alignParentRight="true" 
    android:text="gfhfgh" 
    android:textSize="25sp" /> 

</RelativeLayout 
1

Попробуйте это ...

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:orientation="horizontal" > 

    <LinearLayout 
    android:gravity="center" 
    android:layout_width="wrap_content" 
    android:layout_height="match_parent" > 

    <CheckBox 
     android:id="@+id/checkBox1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" /> 
    </LinearLayout> 

    <TextView 
    android:id="@+id/textView_Item_Listview" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:padding="3dp" 
    android:text="gfhfgh" 
    android:textSize="25sp" /> 

</LinearLayout> 

ИЛИ

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:orientation="horizontal" > 

    <CheckBox 
    android:id="@+id/checkBox1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="gfhfgh" /> 

</LinearLayout> 

Вы можете установить текст CheckBox вместо того, чтобы использовать другие TextView

Смежные вопросы