繁体   English   中英

我的TextView没有显示...为什么?

[英]My TextView is not showing…Why?

我试图用它下面的TextView创建一个ListView。 为此,我要向ListView添加页脚。 我想要ListView和TextView之间有一条线,但是我希望它有特定的边距。 我创建了一种样式,然后将其添加到页脚中。 当我添加带有样式的视图时,它将文本完全推离屏幕。 这是ListView:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
    android:orientation="vertical" >

    <ListView
        android:id="@+id/list_view_order_filter"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_marginTop="15dp"
        android:layout_weight="1" >
    </ListView>

  <LinearLayout
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:layout_gravity="bottom"
      android:orientation="horizontal" >

      <Button
          android:id="@+id/orderFilters"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:layout_weight="1"
          android:text="@string/order_filter" >
      </Button>

      <Button
          android:id="@+id/orderFiltersCancel"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:layout_weight="1"
          android:text="@string/cancel" >
      </Button>
  </LinearLayout>

</LinearyLayout>

这是我的风格:

<style name="divider">
    <item name="android:layout_width">match_parent</item>
    <item name="android:layout_height">1dp</item>
    <item name="android:layout_marginRight">15dp</item>
    <item name="android:layout_marginLeft">15dp</item>
    <item name="android:layout_marginTop">10dp</item>
    <item name="android:background">?android:attr/listDivider</item>
</style>

这是我的页脚:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >

    <View style="@style/divider" />

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" 
        android:layout_weight="1">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="15dp"
            android:layout_marginRight="15dp"
            android:gravity="left"
            android:text="@string/total"
            android:textStyle="bold" />

        <TextView
            android:id="@+id/orderTotal"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginRight="15dp"
            android:gravity="right"
            android:textIsSelectable="true" />
    </LinearLayout>

</LinearLayout>

这是我的视图的屏幕截图。
在此处输入图片说明

页脚中的LinearLayout是水平的,但使用style =“ @ style / divider”的视图具有layout_width:match_parent。 它会将随后出现的所有内容都推离屏幕。

这是@ style / divider中“ match_parent”的问题

{

<item name="android:layout_width">20dp</item>

<item name="android:layout_height">1dp</item>

<item name="android:layout_marginRight">15dp</item>

<item name="android:layout_marginLeft">15dp</item>

<item name="android:layout_marginTop">10dp</item>

<item name="android:background">?android:attr/listDivider</item>

}

试试这个,您将可以看到您的视图,然后根据需要调整宽度

您可以将线性布局设为垂直

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="40dp" >

<View style="@style/divider" />

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:orientation="horizontal" >

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="15dp"
        android:layout_marginRight="15dp"
        android:gravity="left"
        android:text="12000000"
        android:textStyle="bold" />

    <TextView
        android:id="@+id/orderTotal"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginRight="15dp"
        android:gravity="right"
        android:textIsSelectable="true" />
</LinearLayout>

试试这个代码。 在这里,我将您的主要xml和页脚合并到一个文件中。 根据您的要求进行编辑

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<ListView
    android:id="@+id/list_view_order_filter"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_marginTop="15dp"
    android:layout_weight="1" >
</ListView>

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom"
    android:orientation="horizontal" >

    <Button
        android:id="@+id/orderFilters"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="order_filter" >
    </Button>

    <Button
        android:id="@+id/orderFiltersCancel"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="cancel" >
    </Button>
</LinearLayout>



    <View
        android:layout_width="fill_parent"
        android:layout_height="1dp"
        android:background="@drawable/icon" />

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

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="15dp"
            android:layout_marginRight="15dp"
            android:gravity="left"
            android:text="total"
            android:textColor="#3a6e9a"
            android:textStyle="bold" />

        <TextView
            android:id="@+id/orderTotal"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginRight="15dp"
            android:gravity="right"
            android:text="left"
            android:textColor="#3a6e9a" />
    </LinearLayout>

    </LinearLayout>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM