1

The following is the code of main.xml, which i have used to create a row adapter for JSON

 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="4dp"
android:orientation="vertical"
android:weightSum="1">
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">

<LinearLayout
    android:orientation="horizontal"
    android:layout_width="wrap_content"
    android:layout_height="50dp"
    android:layout_weight="0.88"
    >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:text="pumpName"
        android:id="@+id/tvPump" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:text="Time"
        android:id="@+id/tvTime"
        android:gravity="center_vertical" />

</LinearLayout>

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

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/ivIcon"
        android:src="@drawable/yes" />
</FrameLayout>
</LinearLayout>
</LinearLayout>

The above code produces no error but the Time TextView does not come at the center.

I have tried android:gravity="center" but it did not work.

This is the image of my android studio

emrekose26
  • 683
  • 1
  • 8
  • 21
Mohendra
  • 161
  • 1
  • 7

1 Answers1

1

Relative Layout could come in handy here like so:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="4dp">

    <TextView
        android:id="@+id/tvPump"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:text="pumpName"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <TextView
        android:id="@+id/tvTime"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:gravity="center"
        android:text="Time"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <ImageView
        android:layout_width="wrap_content"
        android:id="@+id/ivIcon"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true"
        android:layout_height="wrap_content"
        android:src="@drawable/yes" />

</RelativeLayout>
Bill
  • 4,506
  • 2
  • 18
  • 29