列表视图元素高度
List view element height
我有以下问题。我的列表视图元素由两个排成一行的按钮组成:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/item_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="5dp">
<Button
android:id="@+id/time_field"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/task_field"
android:layout_alignTop="@+id/task_field"
android:layout_centerVertical="true"
android:layout_marginEnd="5dp"
android:layout_marginRight="5dp"
android:clickable="false"
android:enabled="true"
android:focusable="false"
android:focusableInTouchMode="false"
android:longClickable="false"
android:paddingLeft="2dp"
android:paddingRight="2dp"
android:textColor="@color/black_col" />
<Button
android:id="@+id/task_field"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toEndOf="@+id/time_field"
android:clickable="false"
android:enabled="true"
android:focusable="false"
android:focusableInTouchMode="false"
android:gravity="center|start"
android:longClickable="false"
android:paddingLeft="10dp"
android:paddingRight="10dp"/>
所以在应用程序中发生的情况是,第二个(右)按钮被文本(由用户)填充,可以是 2、3 或更多行,而左按钮中的文本始终是单行的线。所以,我想要的是让第一个(左)按钮始终与右按钮具有相同的高度,这取决于文本行的数量。此外,左侧按钮中的文本行应位于中间。
现在我只能制作等高的按钮(使用layout_alignBottom和layout_alignTop)但是左边按钮中的文本总是在最上面。
据我了解,这是由于列表视图项的渲染在设置高度后完成,但我不知道如何克服这个问题。我试图在我的列表视图适配器中以编程方式将左按钮高度设置为等于右按钮高度,但它仅在我点击列表视图项目时有帮助,而不是在列表被填充或滚动时!
请帮助我克服这个问题!谢谢!
因此,没有调整文本大小的本机方法 view.But 您可以在 Auto Scale TextView Text to Fit within Bounds 上找到有用的实现
或者您可以调整文本大小以适应边界。查看此内容以获得更多帮助 How to adjust text font size to fit textview
我有以下问题。我的列表视图元素由两个排成一行的按钮组成:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/item_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="5dp">
<Button
android:id="@+id/time_field"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/task_field"
android:layout_alignTop="@+id/task_field"
android:layout_centerVertical="true"
android:layout_marginEnd="5dp"
android:layout_marginRight="5dp"
android:clickable="false"
android:enabled="true"
android:focusable="false"
android:focusableInTouchMode="false"
android:longClickable="false"
android:paddingLeft="2dp"
android:paddingRight="2dp"
android:textColor="@color/black_col" />
<Button
android:id="@+id/task_field"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toEndOf="@+id/time_field"
android:clickable="false"
android:enabled="true"
android:focusable="false"
android:focusableInTouchMode="false"
android:gravity="center|start"
android:longClickable="false"
android:paddingLeft="10dp"
android:paddingRight="10dp"/>
所以在应用程序中发生的情况是,第二个(右)按钮被文本(由用户)填充,可以是 2、3 或更多行,而左按钮中的文本始终是单行的线。所以,我想要的是让第一个(左)按钮始终与右按钮具有相同的高度,这取决于文本行的数量。此外,左侧按钮中的文本行应位于中间。
现在我只能制作等高的按钮(使用layout_alignBottom和layout_alignTop)但是左边按钮中的文本总是在最上面。
据我了解,这是由于列表视图项的渲染在设置高度后完成,但我不知道如何克服这个问题。我试图在我的列表视图适配器中以编程方式将左按钮高度设置为等于右按钮高度,但它仅在我点击列表视图项目时有帮助,而不是在列表被填充或滚动时!
请帮助我克服这个问题!谢谢!
因此,没有调整文本大小的本机方法 view.But 您可以在 Auto Scale TextView Text to Fit within Bounds 上找到有用的实现 或者您可以调整文本大小以适应边界。查看此内容以获得更多帮助 How to adjust text font size to fit textview