【问题标题】:TextView overwritesTextView 覆盖
【发布时间】:2014-08-06 21:15:50
【问题描述】:

我想知道如何解决这个问题。

现在我的情况是这样的: 我有一个包含项目的列表视图。一个项目由一个标题(textview)和一个固定在右侧的数字(textview)组成(以圆形可绘制形状为背景的textview。)

但我的问题是当我的标题太长时它会覆盖数字。

我想知道如何编码我的布局,我的标题根本不会覆盖其他文本视图。这样数字的左边就会有一条假想的线。如果标题太长,它会放在下一行,不会覆盖我的号码。

感谢您的帮助!

这是我的列表项代码:

**custom_list_item.xml:**

<?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:background="@color/transparent"
    android:paddingTop="10dp" >

    <TextView
        android:id="@+id/tvFach"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:layout_marginBottom="10dp"
        android:text="@string/fach_grid"
        android:textColor="@color/white"
        android:paddingLeft="5dp"
        android:textSize="30sp" />

    <TextView
        android:id="@+id/tvAverage"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_centerVertical="true"
        android:layout_marginBottom="10dp"
        android:layout_marginRight="10dp"
        android:background="@drawable/circle_list_item"
        android:text="@string/average"
        android:textColor="@color/white"
        android:textSize="30sp" />

    <View
        android:id="@+id/separator"
        android:layout_width="fill_parent"
        android:layout_height="1dip"
        android:layout_alignParentBottom="true"
        android:layout_marginBottom="10dp"
        android:background="@color/white" />

</RelativeLayout>

【问题讨论】:

  • LinearLayout 可以,RelativeLayout 并不是为了禁止重叠而设计的。

标签: android listview textview restrict


【解决方案1】:

我会试试这个:

    <?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:background="@color/black"
    android:paddingTop="10dp" >

 <ImageView
        android:id="@+id/tvAverageImage"
        android:layout_width="wrap_content"
        android:layout_centerVertical="true"
        android:layout_height="wrap_content"
        android:layout_marginBottom="10dp"
        android:src="@drawable/ic_menu_mark"
        android:layout_alignParentRight="true"
        android:paddingLeft="5dp" />

    <TextView
        android:id="@+id/tvAverage"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:layout_marginBottom="10dp"
        android:layout_alignParentRight="true"
        android:text="average"
        android:textColor="@color/white"
        android:paddingLeft="5dp"
        android:textSize="30sp" />

    <TextView
        android:id="@+id/tvFach"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_toLeftOf="@id/tvAverage"
        android:layout_centerVertical="true"
        android:layout_marginBottom="10dp"
        android:layout_marginRight="10dp"
        android:text="fach_grid"
        android:textColor="@color/white"
        android:textSize="30sp" />

    <View
        android:id="@+id/separator"
        android:layout_width="fill_parent"
        android:layout_height="1dip"
        android:layout_alignParentBottom="true"
        android:layout_marginBottom="10dp"
        android:background="@color/white" />

</RelativeLayout>

【讨论】:

  • 或者你可以做一个水平方向的线性布局
  • 那个问题是我的号码是即使它的alignParentRight = true,我的号码就在标题的旁边(在圆圈中),并且圆圈从标题之后一直延伸到列表项的末尾
  • Still doesn't work number is still right next after the title and background is still stretched!但是已经感谢您的提示了!
  • tvAverage textview 应该是一个设定的宽度吗?如果您设置背景并让视图调整大小,它将始终拉伸。您可以在文本视图后面使用图像视图。
  • 你到底是什么意思?我怎样才能做到这一点?
猜你喜欢
  • 2011-08-30
  • 1970-01-01
  • 2020-09-10
  • 2013-05-06
  • 2011-07-02
  • 2017-10-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多