android - 另一个文本视图的右侧和中心垂直文本
问题描述
我有两个文本视图。一 - 文本持有人,第二 - 计数持有人。当文本持有者是一个宽度时,一切似乎都是正确的。但是当文本是两个或更多字符串时,我的文本视图数量会离开屏幕。(看屏幕)。我尝试了相对和约束,但都不起作用
<?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="wrap_content"
xmlns:tools="http://schemas.android.com/tools"
android:background="?android:attr/selectableItemBackground"
android:clickable="true"
android:focusable="true"
android:orientation="horizontal"
android:padding="@dimen/margin_general_16dp">
<TextView
android:id="@+id/testText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingStart="@dimen/margin_general_16dp"
android:textColor="@color/text_color_general"
android:textSize="@dimen/text_size_general"
tools:text="Test test test Test test test Test test test Test test test Test test test Test test test"/>
<TextView
android:id="@+id/testAmount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/margin_small_8dp"
android:textColor="@color/redorange"
android:textSize="@dimen/text_size_general"
tools:text="50"/>
</LinearLayout>
解决方案
使用以下代码:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="horizontal">
<TextView
android:id="@+id/testText"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
tools:text="Test test test Test test test Test test test Test test test Test test test Test test test"/>
<TextView
android:id="@+id/testAmount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
tools:text="50"/>
</LinearLayout>
推荐阅读
- symfony - Shopify 应用程序开发中的 Inventory_items.json 问题
- php - 如何在不重新加载页面的情况下更新选择选项值(模态)
- python - PermissionError: [Errno 13] 使用熊猫加载文件时权限被拒绝错误
- hashicorp-vault - 在企业组织中保护 HashiCorp Vault 的 kv2 秘密引擎的秘密群体
- ios - 未找到 -lboost_context 的库
- python - 无效的块标记“其他”。您是否忘记注册或加载此标签?
- wordpress - Wordpress 上的规范页面
- automation - Ansible cisco ios,改变接口上的vlan
- javascript - Javascript - 寻找一种转换父子关系的方法
- elasticsearch - 由于控制进程收到致命信号(code=killed, signal=9/KILL),无法启动 elasticsearch