Android Can';无法在布局中获得正确的文本视图
这就是我需要实现的目标: |文本视图1 |文本视图2 |按钮| TV1可以任意增长,但只占用显示内部文本所需的空间。如果文本大于它的空格,那么它将省略。 TV2必须始终位于TV1文本的右侧,并且必须显示其所有内容。它不能有省略。它总是要显示它的文本。 TV1和TV2为单线。 按钮固定在屏幕右侧 例1: TV1=这是一个文本过长的文本 TV2=1923Android Can';无法在布局中获得正确的文本视图,android,mobile,layout,Android,Mobile,Layout,这就是我需要实现的目标: |文本视图1 |文本视图2 |按钮| TV1可以任意增长,但只占用显示内部文本所需的空间。如果文本大于它的空格,那么它将省略。 TV2必须始终位于TV1文本的右侧,并且必须显示其所有内容。它不能有省略。它总是要显示它的文本。 TV1和TV2为单线。 按钮固定在屏幕右侧 例1: TV1=这是一个文本过长的文本 TV2=1923 |这是一个文本W…1923按钮| 例2: TV1=仅此而已 TV2=1923 |就是这个1923年的按钮| (忽略下划线) 我尝试了上千种不同
|这是一个文本W…1923按钮| 例2: TV1=仅此而已 TV2=1923
|就是这个1923年的按钮| (忽略下划线) 我尝试了上千种不同的组合,包括重量、包装内容等。。。但还是没能把它做好
救命啊 我为你创造了一些小东西,我想这就是你想要的。我相信你可能不知道的是maxLength和单线部分
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:maxWidth="100dp"
android:singleLine="true"
android:text="I Just this helo this is long"
android:layout_height="wrap_content"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
<Button
android:layout_width="wrap_content"
android:layout_alignParentRight="true"
android:layout_height="wrap_content"/>
</RelativeLayout>
这是您需要的尺寸,以达到您想要的合身度。在这些xml属性之后,您可以添加想要应用的任何其他样式,如颜色或文本。我给这一行加了星号,因为这将阻止它垂直生长。如果您希望文本在小于屏幕的情况下对齐一行,请仅将android:gravity=“right”添加到tv1。试试这个
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="@+id/textview1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_weight="1.0"
android:text="textview1" />
<TextView
android:id="@+id/textview2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="@+id/textview1"
android:layout_weight="1.0"
android:text="textview2" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1.0"
android:text="button"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="@+id/textview1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_weight="1.0"
android:text="textview1" />
<TextView
android:id="@+id/textview2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="@+id/textview1"
android:layout_weight="1.0"
android:text="textview2" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1.0"
android:text="button"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
</RelativeLayout>