代码之家  ›  专栏  ›  技术社区  ›  AppiDevo

android布局:TextView右侧的TextView

  •  0
  • AppiDevo  · 技术社区  · 8 年前

    我需要显示以下内容的布局:

    1. cl\u tv\u团队名称 cl\u tv\u团队名称 cl\u tv\u团队名称 和(Q)符号相邻)
    2. 有长文本,textview用两行或多行显示,但(Q)符号是 仍然可见 在右侧

    易于理解的 LinearLayout 不起作用。文本框

    <LinearLayout 
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
    
    
        <TextView
            android:id="@+id/cl__tv_team_name"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="asdfa asdfasf asdf asdf asf dsafasd fads fasdf asdfsad asdf dsaf asfd safa" />
    
        <TextView
        android:id="@+id/cl__tv_q_sign"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="(Q)" />
    
    </LinearLayout>
    

    我也试过了 RelativeLayout 没有适当的效果:

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical">
    
        <TextView
            android:id="@+id/cl__tv_team_name"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:layout_centerVertical="true"
            android:text="asdfa asdfasf asdf asdf asf dsafasd fads fasdf asdfsad asdf dsaf asfd safa" />
    
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentEnd="true"
            android:layout_alignParentRight="true"
            android:layout_centerVertical="true"
            android:layout_toEndOf="@+id/cl__tv_team_name"
            android:layout_toRightOf="@+id/cl__tv_team_name"
            android:text="(Q)"
            android:textSize="13sp" />
    </RelativeLayout>
    
    4 回复  |  直到 8 年前
        1
  •  3
  •   Ben P.    8 年前

    ConstraintLayout 为此:

    <?xml version="1.0" encoding="utf-8"?>
    <android.support.constraint.ConstraintLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    
        <TextView
            android:id="@+id/text"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:text="short text"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toLeftOf="@+id/q"
            app:layout_constraintWidth_default="wrap"
            app:layout_constraintHorizontal_chainStyle="packed"
            app:layout_constraintHorizontal_bias="0"/>
    
        <TextView
            android:id="@+id/q"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="(Q)"
            app:layout_constraintLeft_toRightOf="@+id/text"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintBaseline_toBaselineOf="@+id/text"/>
    
    </android.support.constraint.ConstraintLayout>
    

    enter image description here

    或者让第一个视图中的文本非常长:

    enter image description here

        2
  •  0
  •   Peter Stewart    8 年前

    尝试在相对布局内混合使用垂直线性布局和水平线性布局。听起来令人困惑,但它通常有效。

        3
  •  0
  •   Luca Nicoletti    8 年前

    这应该行得通

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical">
    
            <TextView
                android:id="@+id/q_sign"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentEnd="true"
                android:layout_alignParentRight="true"
                android:layout_centerVertical="true"
                android:text="(Q)"
                android:textSize="13sp" />
    
            <TextView
                android:id="@+id/cl__tv_team_name"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:layout_alignParentStart="true"
                android:layout_centerVertical="true"
                android:layout_toStartOf="@+id/q_sign"
                android:layout_toLeftOf="@+id/q_sign"
                android:text="asdfa asdfasf asdf asdf asf dsafasd fads fasdf asdfsad asdf dsaf asfd safa" />
    
    </RelativeLayout>
    
        4
  •  0
  •   sumanhaque    8 年前

    <?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"
        android:orientation="horizontal">
    
        <TextView
            android:id="@+id/cl__tv_team_name"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="asdfa asdfasf asdf asdf asf dsafasd fads fasdf asdfsad asdf dsaf asfd safa" />
    
        <TextView
            android:id="@+id/cl__tv_q_sign"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="(Q)" />
    </LinearLayout>