首页 > 解决方案 > 另一个文本视图的右侧和中心垂直文本

问题描述

我有两个文本视图。一 - 文本持有人,第二 - 计数持有人。当文本持有者是一个宽度时,一切似乎都是正确的。但是当文本是两个或更多字符串时,我的文本视图数量会离开屏幕。(看屏幕)。我尝试了相对和约束,但都不起作用

<?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>

标签: androidandroid-layoutandroid-xml

解决方案


使用以下代码:

<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>

推荐阅读