在 RelativeLayout 中看不到 TextView
Can't see a TextView in a RelativeLayout
我用 RelativeLayout 做了一个 XML,代码如下:
我看不到 ID 为 "TV_voucher_number" 的 TextView。
我试过可能使 XML 成为滚动视图,但后来我无法正确看到 ListView。
代码:
<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>
实际上您已将 android:layout_height="match_parent"
设置为 ProductsList
,这覆盖了 TV_voucher_number
高度。这可能是问题所在。
希望对您有所帮助。
更新
<?xml version="1.0" encoding="utf-8"?>
<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/buttons_bg"
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/buttons_bg"
>
</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/buttons_bg"
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/buttons_bg"
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/buttons_bg"
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/buttons_bg"
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/buttons_bg"
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/buttons_bg"
android:textSize="12dp"
android:textStyle="bold"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true">
</TextView>
<LinearLayout
android:id="@+id/ll_ListView"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/TV_products_title"
android:weightSum="3">
<ListView
android:id="@+id/ProductsList"
android:layout_height="0dp"
android:layout_width="match_parent"
android:layout_weight="2"
>
</ListView>
<TextView
android:id="@+id/voucher_number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/buttons_bg"
android:layout_below="@id/ProductsList"
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:layout_below="@id/ll_ListView"
android:textColor="@color/buttons_bg"
android:text="Hello Wrord"
android:textSize="12dp">
</TextView>
<TextView
android:id="@+id/tv_Ref"
android:layout_width="wrap_content"
android:layout_below="@id/TV_voucher_number"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:textColor="@color/row_body_background_even"
android:text="REF #"
android:textSize="12dp"
android:textStyle="bold">
</TextView>
</LinearLayout>
</RelativeLayout>
尝试将最后 3 个文本视图放在相对布局中,如下所示:
<RelativeLayout
android:id="@+id/hello"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/ProductsList">
<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:layout_below="@+id/voucher_number"
android:text="HELLO"
android:textSize="12dp">
</TextView>
<TextView
android:layout_width="wrap_content"
android:layout_below="@id/TV_voucher_number"
android:layout_marginTop="20dp"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:text="REF #"
android:textSize="12dp"
android:textStyle="bold">
</TextView>
</RelativeLayout>
试试这个:
<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>
基本上,您只需将列表视图设置在 bottom_layout 上方,并将 bottom_layout 设为 alightParentBottom。希望这就是您想要的;)
将此 TextView
的高度更改为 wrap_content,如下所示:
<TextView
android:id="@+id/voucher_number"
android:layout_marginTop="20dp"
android:layout_below="@id/ProductsList"
android:layout_width="wrap_content"
android:layout_height="wrap_content" //THIS GUY
android:text="VOUCHER #"
android:textSize="12dp"
android:textStyle="bold">
</TextView>
当然还要将文本设置为 TV_voucher_number
。
效果很好
我用 RelativeLayout 做了一个 XML,代码如下: 我看不到 ID 为 "TV_voucher_number" 的 TextView。 我试过可能使 XML 成为滚动视图,但后来我无法正确看到 ListView。 代码:
<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>
实际上您已将 android:layout_height="match_parent"
设置为 ProductsList
,这覆盖了 TV_voucher_number
高度。这可能是问题所在。
希望对您有所帮助。
更新
<?xml version="1.0" encoding="utf-8"?>
<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/buttons_bg"
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/buttons_bg"
>
</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/buttons_bg"
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/buttons_bg"
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/buttons_bg"
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/buttons_bg"
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/buttons_bg"
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/buttons_bg"
android:textSize="12dp"
android:textStyle="bold"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true">
</TextView>
<LinearLayout
android:id="@+id/ll_ListView"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/TV_products_title"
android:weightSum="3">
<ListView
android:id="@+id/ProductsList"
android:layout_height="0dp"
android:layout_width="match_parent"
android:layout_weight="2"
>
</ListView>
<TextView
android:id="@+id/voucher_number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/buttons_bg"
android:layout_below="@id/ProductsList"
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:layout_below="@id/ll_ListView"
android:textColor="@color/buttons_bg"
android:text="Hello Wrord"
android:textSize="12dp">
</TextView>
<TextView
android:id="@+id/tv_Ref"
android:layout_width="wrap_content"
android:layout_below="@id/TV_voucher_number"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:textColor="@color/row_body_background_even"
android:text="REF #"
android:textSize="12dp"
android:textStyle="bold">
</TextView>
</LinearLayout>
</RelativeLayout>
尝试将最后 3 个文本视图放在相对布局中,如下所示:
<RelativeLayout
android:id="@+id/hello"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/ProductsList">
<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:layout_below="@+id/voucher_number"
android:text="HELLO"
android:textSize="12dp">
</TextView>
<TextView
android:layout_width="wrap_content"
android:layout_below="@id/TV_voucher_number"
android:layout_marginTop="20dp"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:text="REF #"
android:textSize="12dp"
android:textStyle="bold">
</TextView>
</RelativeLayout>
试试这个:
<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>
基本上,您只需将列表视图设置在 bottom_layout 上方,并将 bottom_layout 设为 alightParentBottom。希望这就是您想要的;)
将此 TextView
的高度更改为 wrap_content,如下所示:
<TextView
android:id="@+id/voucher_number"
android:layout_marginTop="20dp"
android:layout_below="@id/ProductsList"
android:layout_width="wrap_content"
android:layout_height="wrap_content" //THIS GUY
android:text="VOUCHER #"
android:textSize="12dp"
android:textStyle="bold">
</TextView>
当然还要将文本设置为 TV_voucher_number
。
效果很好