1

enter image description here

I want to display text field Duration below the text field Item.I am having the list view which is populated in different for even and odd rows. But the thing is I want the two text field in parallel to image I want to display vertically, but when I put the two text field in the Liner Vertical layout it shows error. How to display the two text field in vertical manner. Sorry if any mistake in my english. Thanks in advance.

Below is my code:

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal" >
        <ImageView
            android:id="@+id/gender_image"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="39.5"
            android:contentDescription="@string/app_name"
            android:src="@drawable/male" />
        <TextView
            android:id="@+id/name"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_weight="60"
            android:gravity="center"
            android:textColor="@android:color/holo_green_dark" />
        <TextView
            android:id="@+id/name1"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_weight="60"
            android:gravity="center"
            android:textColor="@android:color/holo_green_light" />
    </LinearLayout>
droidev
  • 7,352
  • 11
  • 62
  • 94
Praveenkumar
  • 119
  • 3
  • 12

4 Answers4

3
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<ImageView
    android:id="@+id/gender_image"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_weight="39.5"
    android:contentDescription="@string/app_name"
    />
<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical">
    <TextView
        android:id="@+id/name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_weight="60"
        android:gravity="center"
        android:textColor="@android:color/holo_green_dark" />
    <TextView
        android:id="@+id/name1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_weight="60"
        android:gravity="center"
        android:textColor="@android:color/holo_green_light" />
</LinearLayout>  

Try this!!! It will give the view, what you are looking till.

Narendra Baratam
  • 828
  • 1
  • 12
  • 26
3

Please check below my code here i manage your both different item view in single layout so you have just show/hide respective layout based on item :

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:gravity="center">

    <LinearLayout
        android:id="@+id/male_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

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

            <ImageView
                android:id="@+id/gender_image_male"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:adjustViewBounds="true"
                android:contentDescription="@string/app_name"
                android:src="@drawable/male" />
        </LinearLayout>

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

            <TextView
                android:id="@+id/name_male"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:textColor="@android:color/holo_green_dark" />

            <TextView
                android:id="@+id/name1_male"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:textColor="@android:color/holo_green_light" />
        </LinearLayout>

    </LinearLayout>

    <LinearLayout
        android:id="@+id/female_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

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

            <ImageView
                android:id="@+id/gender_image_female"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:adjustViewBounds="true"
                android:contentDescription="@string/app_name"
                android:src="@drawable/female" />
        </LinearLayout>

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

            <TextView
                android:id="@+id/name_female"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:textColor="@android:color/holo_green_dark" />

            <TextView
                android:id="@+id/name1_female"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:textColor="@android:color/holo_green_light" />
        </LinearLayout>

    </LinearLayout>
</LinearLayout>

Note : android:layout_weight is used take rest of area.

Haresh Chhelana
  • 24,720
  • 5
  • 57
  • 67
2

use this ->

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal" >
    <ImageView
        android:id="@+id/gender_image"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="39.5"
        android:contentDescription="@string/app_name"
        android:src="@drawable/male" />

    <LinearLayout
        android:layout_weight="60.5"
        android:orientation="vertical"
        android:layout_width="0dp"
        android:layout_height="match_parent">

        <TextView
            android:id="@+id/name"
            android:text="asdasdas"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_weight="60"
            android:gravity="center"
            android:textColor="@android:color/holo_green_dark" />
        <TextView
            android:id="@+id/name1"
            android:text="asdasd"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_weight="60"
            android:gravity="center"
            android:textColor="@android:color/holo_green_light" />

    </LinearLayout>

</LinearLayout>
Zahidul Islam
  • 3,180
  • 1
  • 25
  • 35
  • android:layout_weight="60.5" why it is given as 60.5 and what is difference b/w android:layout_weight and android:layout_width? Pls explain I am new to android. – Praveenkumar Nov 27 '15 at 06:18
  • think like that total width is 100%, you take 39.5% for image , rest of the area for the TextViews layout. So, 100-39.5 = 60.5 . But it's not mendaroty to think like 100%. it may be 115 , 200 or any size . – Zahidul Islam Nov 27 '15 at 07:39
  • Thanks for u r comment. – Praveenkumar Nov 27 '15 at 07:43
2
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal" >
    <ImageView
        android:id="@+id/gender_image"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="39.5"
        android:contentDescription="@string/app_name"
        android:src="@drawable/male"  />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >
    <TextView
        android:id="@+id/name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="60"
        android:gravity="center"
        android:textColor="@android:color/holo_green_dark" />
    <TextView
        android:id="@+id/name1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="60"
        android:gravity="center"

        android:textColor="@android:color/holo_green_light" />
        </LinearLayout>

</LinearLayout>

PS: put the weights and width accordingly... :)

DGN
  • 702
  • 3
  • 12