Walid Hossain
Walid Hossain

Reputation: 2714

Android Layout positioning incorrectly

I'm trying to create a layout for list child. Here is what it should look like: enter image description here

But when the text for Name is large it is displaced like: enter image description here

I'm using the following code

<?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="35dp"
    android:background="@color/text_blue"
    android:orientation="horizontal"
    android:weightSum="51" >

    <TextView
        android:id="@+id/tranID"
        android:layout_width="fill_parent"
        android:layout_height="34dp"
        android:layout_marginBottom="1dp"
        android:layout_marginRight="1dp"
        android:layout_weight="11"
        android:background="@color/app_bg"
        android:gravity="center_vertical|center_horizontal"
        android:lines="2"
        android:text="@string/tranid"
        android:textSize="9sp" />

    <TextView
        android:id="@+id/name"
        android:layout_width="fill_parent"
        android:layout_height="34dp"
        android:layout_marginBottom="1dp"
        android:layout_marginRight="1dp"
        android:layout_weight="9"
        android:background="@color/app_bg"
        android:gravity="center_vertical|center_horizontal"
        android:lines="2"
        android:text="@string/name"
        android:textSize="9sp" />

    <TextView
        android:id="@+id/number"
        android:layout_width="fill_parent"
        android:layout_height="34dp"
        android:layout_marginBottom="1dp"
        android:layout_marginRight="1dp"
        android:layout_weight="10"
        android:background="@color/app_bg"
        android:gravity="center_vertical|center_horizontal"
        android:lines="2"
        android:text="@string/phone"
        android:textSize="9sp" />

    <TextView
        android:id="@+id/date"
        android:layout_width="fill_parent"
        android:layout_height="34dp"
        android:layout_marginBottom="1dp"
        android:layout_marginRight="1dp"
        android:layout_weight="10"
        android:background="@color/app_bg"
        android:gravity="center_vertical|center_horizontal"
        android:lines="2"
        android:text="@string/date"
        android:textSize="9sp" />

    <TextView
        android:id="@+id/amount"
        android:layout_width="fill_parent"
        android:layout_height="34dp"
        android:layout_marginBottom="1dp"
        android:layout_weight="11"
        android:background="@color/app_bg"
        android:gravity="center_vertical|center_horizontal"
        android:lines="2"
        android:text="@string/amount"
        android:textSize="9sp" />

</LinearLayout>

I need it emergency. Would you like to help me?

Upvotes: 0

Views: 64

Answers (2)

Triode
Triode

Reputation: 11359

Give layout_height like below for the TextView.enter image description here

android:layout_height="fill_parent"

Upvotes: 2

user2157571
user2157571

Reputation:

you can try: android:singleline="true"

Upvotes: 0

Related Questions