Reputation: 119
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>
Upvotes: 1
Views: 820
Reputation: 24848
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.
Upvotes: 3
Reputation: 828
<?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.
Upvotes: 3
Reputation: 702
<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... :)
Upvotes: 2
Reputation: 3190
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>
Upvotes: 2