0

I want to arrange like : image-text-checkbox

But I couldnt achieve it. android:layout_toRightOf , android:layout_alignParentRight="true" .etc didnt work ! maybe its because of inflating, I dont know !

![enter image description here][1]

Code:

RelativeLayout v = (RelativeLayout) mInflater.inflate(R.layout.result_checkbox, null);
           final TextView titleui = (TextView) v.findViewById(R.id.titleui);
               titleui.setText(mytext);
....

          tableView.addViewItem(v2);
         ViewItem v2 = new ViewItem(v);     
        tableView.addViewItem(v2);

xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"  
    android:duplicateParentState="true" 
    android:paddingLeft="10dip"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:minHeight="40dip">

      <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <TextView android:text="Versão" 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" 
        android:id="@+id/titleui"
        android:gravity="center_vertical"
        android:layout_centerVertical="true" />

    <CheckBox
 android:id="@+id/cbox"
 android:layout_width="match_parent"
 android:layout_height="wrap_content" />

</RelativeLayout>
santral
  • 87
  • 1
  • 1
  • 8

1 Answers1

0

Using Relative layout

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"  
android:duplicateParentState="true" 
android:paddingLeft="10dip"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:minHeight="40dip">

  <ImageView
    android:id="@+id/imageView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/ic_launcher" />

<TextView android:text="Versão....." 
    android:paddingLeft="20dp"
    android:layout_toRightOf="@+id/imageView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" 
    android:id="@+id/titleui" />

<CheckBox
 android:id="@+id/cbox"
 android:paddingLeft="20dp"
 android:layout_toRightOf="@+id/titleui"
 android:layout_width="match_parent"
 android:layout_height="wrap_content" />
</RelativeLayout>

Using LinearLayout

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
android:duplicateParentState="true" 
android:paddingLeft="10dip"
android:orientation="horizontal"//set orientation hoorizontal as child views appear next to each other
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:minHeight="40dip">

  <ImageView
    android:id="@+id/imageView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/ic_launcher" />

<TextView android:text="Versão....." 
    android:paddingLeft="20dp"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" 
    android:id="@+id/titleui" />

<CheckBox
  android:id="@+id/cbox"
  android:paddingLeft="20dp"
  android:layout_width="match_parent"
  android:layout_height="wrap_content" />
 </LinearLayout>

ImageVIew---- TextView ----- CheckBox

enter image description here

Raghunandan
  • 132,755
  • 26
  • 225
  • 256
  • Really thanks, it worked. I couldnt think padding is important. And I want to ask one more think: is it possible to make checkbox clickable are for all line. I mean when I click text, checkbox will be selected ? – santral Mar 24 '13 at 16:44
  • better to inflate the same layout in a a listview. yes it is possible. – Raghunandan Mar 24 '13 at 16:52
  • Did you know that you can put a Drawable into a text view? It would save you one layout item, there. I'll bet there is even a yellow warning message in your layout, suggesting you do that... – G. Blake Meike Mar 24 '13 at 17:04
  • android:contentDescription="@string/desc". In that case add this to your imageview to get rid of warning. http://stackoverflow.com/questions/9730673/missing-contentdescription-attribute-on-image-in-xml. warning for textview is because i hardcoded a string instead of getting the stting from string.xml – Raghunandan Mar 24 '13 at 17:08