自定义适配器的Textviews不占用屏幕中的指定空间

用户名

我有两个名为的xml文件compliance_details.xmlcompliance_details_row.xml

以下是我的Compliance_details.xml代码

 <?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="match_parent"
        android:orientation="vertical">

        <TableLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <TableRow
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:layout_marginLeft="10dp"
                android:layout_marginTop="15dp">

                <TextView
                    android:id="@+id/taskNameLabel"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_column="1"
                    android:layout_marginRight="70dp"
                    android:layout_weight="3"
                    android:singleLine="true"
                    android:text="TaskName"
                    android:textColor="#000"
                    android:textSize="20sp" />

                <TextView
                    android:id="@+id/dueDateLabel"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_column="1"
                    android:layout_marginRight="20dp"
                    android:layout_weight="1"
                    android:singleLine="true"
                    android:text="Due Date"
                    android:textColor="#000"
                    android:textSize="20sp" />

                <TextView
                    android:id="@+id/ageingLabel"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_column="1"
                    android:layout_marginRight="20dp"
                    android:layout_weight="1"
                    android:singleLine="true"
                    android:text="Ageiging"
                    android:textColor="#000"
                    android:textSize="20sp" />

            </TableRow>

        </TableLayout>

        <ListView
            android:id="@+id/listView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:focusable="false"
            android:focusableInTouchMode="false"
            android:paddingTop="10dp" />

    </LinearLayout>


and following is my compliance_details_row.xml 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="match_parent">


    <TableLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <TableRow
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_marginLeft="10dp"
            android:layout_marginTop="15dp">

            <TextView
                android:id="@+id/taskNameValue"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_column="1"
                android:layout_marginRight="70dp"
                android:layout_weight="3"
                android:singleLine="true"
                android:text="TaskName"
                android:textColor="#000"
                android:textSize="20sp" />

            <TextView
                android:id="@+id/dueDateValue"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_column="1"
                android:layout_marginRight="20dp"
                android:layout_weight="1"
                android:singleLine="true"
                android:text="Due Date"
                android:textColor="#000"
                android:textSize="20sp" />

            <TextView
                android:id="@+id/ageingValue"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_column="1"
                android:layout_marginRight="20dp"
                android:layout_weight="1"
                android:singleLine="true"
                android:text="Ageiging"
                android:textColor="#000"
                android:textSize="20sp" />

        </TableRow>

    </TableLayout>

</LinearLayout>

在我的适配器中,我用Compliance_row.xml扩展了Compliance_details_row.xml。

但是当我这样做时,compliance_details_row的元素会有些失真。在此处输入图片说明

从上图可以看到,合规名称应该在标题下,TaskName但是合规名称有些失真,而且到期日期值也只部分可见。我怎样才能解决这个问题?

德米特里·蒂莫菲蒂(Dmitri Timofti)

您实际上不需要TableLayout即可实现此目的。只需使用带有weightSum的LinearLayout。要获得所需的比例-更改每个TextView的权重值。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal"
    android:weightSum="3">

         <TextView
            android:id="@+id/taskNameValue"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:singleLine="true"
            android:text="TaskName"
            android:textColor="#000"
            android:textSize="20sp" />

        <TextView
            android:id="@+id/dueDateValue"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:singleLine="true"
            android:text="Due Date"
            android:textColor="#000"
            android:textSize="20sp" />

        <TextView
            android:id="@+id/ageingValue"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:singleLine="true"
            android:text="Ageiging"
            android:textColor="#000"
            android:textSize="20sp" />

</LinearLayout>

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

在getView上的自定义适配器中以编程方式添加textviews

来自分类Dev

片段中的自定义阵列适配器

来自分类Dev

如何在Android中自定义适配器?

来自分类Dev

在RecyclerView适配器中设置自定义字体

来自分类Dev

自定义适配器中的setOnItemClickListener

来自分类Dev

自定义视图的适配器中的NullPointerException

来自分类Dev

自定义适配器中的空指针异常

来自分类Dev

在自定义适配器中找不到ViewByID

来自分类Dev

自定义ListView适配器中的NullPointerException

来自分类Dev

自定义适配器的getview中的NullPointerException

来自分类Dev

getView()中的自定义适配器错误

来自分类Dev

在自定义适配器中遍历ListView

来自分类Dev

自定义绑定适配器中的通用lambda

来自分类Dev

自定义适配器getView中的IndexOutOfBounds异常

来自分类Dev

无法更新自定义适配器中的项目

来自分类Dev

画廊的自定义适配器中的 AsyncTask

来自分类Dev

自定义列表适配器中的 getApplicationContext()

来自分类Dev

自定义适配器中的意图

来自分类Dev

Fragment 中的自定义列表适配器

来自分类Dev

从ArrayList动态将textviews添加到自定义适配器

来自分类Dev

如何将两个textViews添加到自定义适配器?

来自分类Dev

自定义适配器的问题

来自分类Dev

ListView的自定义适配器

来自分类Dev

自定义ListView的适配器

来自分类Dev

Android Studio中带有自定义适配器的自定义ListView

来自分类Dev

使用自定义适配器的ListView中的自定义行

来自分类Dev

具有基本适配器列表项的自定义适配器重复

来自分类Dev

Android自定义适配器如何工作?

来自分类Dev

更新Recyclerview的自定义适配器的ViewHolder值

Related 相关文章

热门标签

归档