Search code examples
androidandroid-layouttextviewandroid-relativelayout

Can't see a TextView in a RelativeLayout


I've made a XML with RelativeLayout with the following code: I can't see the TextView with the id "TV_voucher_number". I've tried maybe making the XML a scrollview, but then I can't see the ListView properly. The code:

<RelativeLayout
    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:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.ManageYourTrip.mytguideapp.Voucher" >

    <LinearLayout
        android:id="@+id/voucherTitle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true">
        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:text="Voucher"
            android:textColor="@color/Black"
            android:textSize="24sp"
            android:textStyle="bold"/>
    </LinearLayout>


        <TextView
            android:id="@+id/TV_Date"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:layout_below="@id/voucherTitle"
            android:text="Date: "
            android:textSize="12sp"
            android:textStyle="bold"
            android:textColor="@color/Black"
            >
        </TextView>

    <TextView
        android:id="@+id/TV_voucher_date"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:layout_toRightOf="@id/TV_Date"
        android:layout_below="@id/voucherTitle"
        android:textColor="@color/Black"
        android:textSize="12sp">
    </TextView>

    <TextView
        android:id="@+id/TV_supplier_title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:layout_below="@id/TV_Date"
        android:text="Supplier Details:"
        android:textColor="@color/Black"
        android:textSize="12dp"
        android:textStyle="bold">
    </TextView>

    <TextView
        android:id="@+id/TV_supplier_name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/TV_supplier_title"
        android:textColor="@color/Black"
        android:textSize="12dp">
    </TextView>

    <TextView
        android:id="@+id/LI_TV_suppliers_Address"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/TV_supplier_name"
        android:textColor="@color/Black"
        android:textSize="12dp">
    </TextView>

    <TextView
        android:id="@+id/TV_products_title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:layout_below="@id/LI_TV_suppliers_Address"
        android:text="PRODUCTS"
        android:textColor="@color/Black"
        android:textSize="12dp"
        android:textStyle="bold"
        android:layout_marginLeft="2dp">
    </TextView>

    <TextView
        android:id="@+id/TV_products_quantity"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:layout_below="@id/LI_TV_suppliers_Address"
        android:text="Qty."
        android:textColor="@color/Black"
        android:textSize="12dp"
        android:textStyle="bold"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true">
    </TextView>

    <ListView
        android:id="@+id/ProductsList"
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:layout_below="@id/TV_products_title">
    </ListView>


    <TextView
        android:id="@+id/voucher_number"
        android:layout_marginTop="20dp"
        android:layout_below="@id/ProductsList"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:textColor="@color/Black"
        android:text="VOUCHER #"
        android:textSize="12dp"
        android:textStyle="bold">
        </TextView>

    <TextView
        android:id="@+id/TV_voucher_number"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_below="@id/voucher_number"
        android:textColor="@color/Black"
        android:textSize="12dp">
    </TextView>

    <TextView
        android:layout_width="wrap_content"
        android:layout_below="@id/ProductsList"
        android:layout_marginTop="20dp"
        android:layout_height="match_parent"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true"
        android:textColor="@color/Black"
        android:text="REF #"
        android:textSize="12dp"
        android:textStyle="bold">
    </TextView>


    </RelativeLayout>

Solution

  • Try this:

    <RelativeLayout
        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:paddingBottom="@dimen/activity_vertical_margin"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin"
        tools:context="com.ManageYourTrip.mytguideapp.Voucher" >
    
        <LinearLayout
            android:id="@+id/voucherTitle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true">
            <TextView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:text="Voucher"
                android:textSize="24sp"
                android:textStyle="bold"/>
        </LinearLayout>
    
    
        <TextView
            android:id="@+id/TV_Date"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:layout_below="@id/voucherTitle"
            android:text="Date: "
            android:textSize="12sp"
            android:textStyle="bold"
            >
        </TextView>
    
        <TextView
            android:id="@+id/TV_voucher_date"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:layout_toRightOf="@id/TV_Date"
            android:layout_below="@id/voucherTitle"
            android:textSize="12sp">
        </TextView>
    
        <TextView
            android:id="@+id/TV_supplier_title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:layout_below="@id/TV_Date"
            android:text="Supplier Details:"
            android:textSize="12dp"
            android:textStyle="bold">
        </TextView>
    
        <TextView
            android:id="@+id/TV_supplier_name"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/TV_supplier_title"
            android:textSize="12dp">
        </TextView>
    
        <TextView
            android:id="@+id/LI_TV_suppliers_Address"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/TV_supplier_name"
            android:textSize="12dp">
        </TextView>
    
        <TextView
            android:id="@+id/TV_products_title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:layout_below="@id/LI_TV_suppliers_Address"
            android:text="PRODUCTS"
            android:textSize="12dp"
            android:textStyle="bold"
            android:layout_marginLeft="2dp">
        </TextView>
    
        <TextView
            android:id="@+id/TV_products_quantity"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:layout_below="@id/LI_TV_suppliers_Address"
            android:text="Qty."
            android:textSize="12dp"
            android:textStyle="bold"
            android:layout_alignParentRight="true"
            android:layout_alignParentEnd="true">
        </TextView>
    
        <ListView
            android:id="@+id/ProductsList"
            android:layout_above="@+id/bottom_layout"
            android:layout_below="@+id/TV_products_title"
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"/>
    
        <LinearLayout
            android:id="@+id/bottom_layout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:orientation="horizontal">
    
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical">
    
                <TextView
                    android:id="@+id/voucher_number"
                    android:layout_marginTop="20dp"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="VOUCHER #"
                    android:textSize="12dp"
                    android:textStyle="bold">
                </TextView>
    
                <TextView
                    android:id="@+id/TV_voucher_number"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="123"
                    android:textSize="12dp">
                </TextView>
    
            </LinearLayout>
    
        </LinearLayout>
    
        <TextView
            android:layout_width="wrap_content"
            android:layout_marginTop="20dp"
            android:layout_height="match_parent"
            android:layout_alignParentRight="true"
            android:layout_below="@+id/ProductsList"
            android:text="REF #"
            android:textSize="12dp"
            android:textStyle="bold">
        </TextView>
    
    </RelativeLayout>
    

    Basically you just need to set your listview above bottom_layout and put your bottom_layout to be alightParentBottom. Hope this is what you want;)