0

我已尝试使用LinearLayout/layout_weightRelativeLayout但无法使布局按预期运行。

我想要做的是一个布局,两个TextViews水平排列,中间有一个分隔符。(包含)布局具有恒定的最大宽度,但可能小于(但不大于)。两者的宽度TextViews应该取决于它们的内容,但也应该有一个上边界,以便它们都适合这个布局。

这是两种情况的可视化:

a) 两者都TextViews适合它们的布局容器,并且应该与中间的分隔符对齐。下面,包含布局由外括号定义,并且可能大于TextViews.

[[abcdefgs][delim][12334345]             ]

(容器)布局宽度可以是wrap_contentfill_parent

b) 两者TextViews都不适合其布局容器的(最大)宽度。然后它们应该均匀地分布在它们的布局内(具有最大宽度)。的文本TextViews然后被截断。

 ..... 50% .....         ..... 50% .....
[[abcdefghijk...][delim][123456789012...]]

有人知道如何实现这一目标吗?

4

1 回答 1

0

我不知道这是否是您想要的(因为您的问题模棱两可),但看看这个布局是否有帮助:

<?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="match_parent" >

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="match_parent" >

        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:ellipsize="end"
            android:text="TextView" />

        <View
            android:layout_width="2dp"
            android:layout_height="fill_parent"
            android:background="#99cc00" />

        <TextView
            android:id="@+id/textView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:ellipsize="end"
            android:text="TextView" />
    </LinearLayout>

    <View
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1" />

</LinearLayout>

其中两者View之间的TextViews代表分隔符。在两者中插入更多文本TextView以查看它们占用的空间。

于 2012-05-29T20:19:44.383 回答