parker
parker

Reputation: 265

close up the gaps between elements in android layout

I am displaying a list of elements in android layout, after displaying the list of elements I observed the gaps between the elements were quite not cool and hence needed to close it up. This is my code snippet

<ImageView
        android:id="@+id/image"
        android:src="@drawable/person"
        android:layout_width="70dp"
        android:layout_height="70dp"
        />

    <TextView
        android:id="@+id/text"
        android:text="Hello1"
        android:textSize="25sp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="5dp"
        android:layout_marginStart="10dp"
        android:layout_toEndOf="@id/image"
        />
    <TextView
        android:id="@+id/triple_status"
        android:text="Contact"
        android:textSize="18sp"
        android:layout_alignStart="@id/text"
        android:layout_below="@id/image"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        />
    <TextView
        android:id="@+id/triple_contact"
        android:text="Email"
        android:textSize="18sp"
        android:layout_marginTop="0dp"
        android:layout_marginBottom="0dp"
        android:layout_alignBaseline="@id/image"
        android:layout_alignBottom="@id/image"
        android:layout_alignParentEnd="true"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

This is the image display of the above snippets

enter image description here

Please how can I close up the gaps. Kindly assist

Upvotes: 1

Views: 57

Answers (3)

Ratilal Chopda
Ratilal Chopda

Reputation: 4220

Please try this one

<?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:orientation="horizontal">

<ImageView
    android:id="@+id/image"
    android:layout_width="70dp"
    android:layout_height="70dp"
    android:src="@mipmap/ic_launcher" />

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_toEndOf="@id/image"
    android:orientation="vertical">

    <TextView
        android:id="@+id/text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="5dp"
        android:text="Hello1"
        android:textSize="25sp" />

    <TextView
        android:id="@+id/triple_status"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toEndOf="@id/image"
        android:text="Contact"
        android:textSize="18sp" />

</LinearLayout>

<TextView
    android:id="@+id/triple_contact"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:layout_centerInParent="true"
    android:layout_marginBottom="0dp"
    android:layout_marginTop="0dp"
    android:text="Email"
    android:textSize="18sp"></TextView>

Upvotes: 1

AskNilesh
AskNilesh

Reputation: 69689

try this

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

<ImageView
    android:id="@+id/image"
    android:layout_width="match_parent"
    android:layout_height="70dp"
    android:layout_weight="1"
    android:src="@drawable/redfox" />

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

    <TextView
        android:id="@+id/text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toEndOf="@id/image"
        android:text="Hello1"
        android:textSize="25sp" />

    <TextView
        android:id="@+id/triple_status"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Contact"
        android:textSize="18sp" />
</LinearLayout>

<TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center_vertical|right"
    android:layout_weight="1"
    android:gravity="right"
    android:text="Email"
    android:textSize="18sp" />

Upvotes: 1

Vasant
Vasant

Reputation: 3575

try this code.

<ImageView
    android:id="@+id/image"
    android:src="@drawable/person"
    android:layout_width="70dp"
    android:layout_height="70dp"
    />

<TextView
    android:id="@+id/text"
    android:text="Hello1"
    android:textSize="25sp"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="5dp"
    android:layout_toEndOf="@id/image"
    />
<TextView
    android:id="@+id/triple_status"
    android:text="Contact"
    android:textSize="18sp"
    android:layout_alignStart="@id/text"
   android:layout_below="@+id/text"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    />
<TextView
    android:id="@+id/triple_contact"
    android:text="Email"
    android:textSize="18sp"
    android:layout_marginTop="15dp"
    android:layout_marginBottom="0dp"
    android:layout_alignBaseline="@id/image"
    android:layout_alignParentEnd="true"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

Upvotes: 1

Related Questions