连续创建等宽TextViews [英] Create TextViews with equal width in a row

查看:156
本文介绍了连续创建等宽TextViews的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建相互旁边3 textviews的布局。该textviews有不同的长度。

I am trying to create a layout with three textviews beside each other. The textviews are of different length.

所有我想要做的是安排他们,使他们始终有平等的layout_width不论其文本的长度。

All I want to do is to arrange them so that they always have equal layout_width irrespective of the length of their text.

途径我想:

1),我尝试使用linear_layout和设置textviews的权重为1,但因为它仅适用于剩下的宽度都textViews定位后没有做到这一点。

1) I tried using linear_layout and setting the weight of textviews to be 1 but that does not do it since it applies only for the remaining width after all textViews are positioned.

2)我也尝试使用表的布局,并通过使用stretchColumns =*拉伸所有列。但还分配所需宽度的文本的长度,然后才它伸展的列

2) I also tried using table layout and stretching all the columns by using stretchColumns="*". but that also allocates the required width to the length of the texts and only then does it stretch the columns.

3)这是一个黑客,但是这是行不通的两种。我想有三个textviews一个相对布局内的线性布局,没有文字,但迫使他们通过设置权重相等宽度。这工作,但后来我想我的下一个这是在相对布局意见,对准自己的权利和线性布局内的意见左边缘。但是,这是行不通的。这是我的布局,我用于此目的。

3) This is a hack but this is not working either. I tried to have a linear layout inside a relative layout with three textviews to have no text but force them to be of equal widths by setting their weights. This works but then I want my next views which are in the relative layout to align themselves to the right and left edges of the views within the linear layout. But this does not work. Here is my layout that I used for this.

        <RelativeLayout
            android:layout_width="fill_parent" android:layout_height="fill_parent" >
            <!-- This is a hack to have all three textviews in a row to obtain equal width -->
            <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal" >
                <TextView android:id="@+id/tv_ref1"
                    android:layout_width="0dp" android:layout_height="wrap_content"
                    android:text="My"
                    android:layout_weight="1.0"
                    android:gravity="center" />
                <TextView android:id="@+id/tv_ref2"
                    android:layout_width="0dp" android:layout_height="wrap_content"
                    android:text="My"
                    android:layout_weight="1.0"
                    android:gravity="center" />
                <TextView android:id="@+id/tv_ref3"
                    android:layout_width="0dp" android:layout_height="wrap_content"
                    android:text="My ghghhfghjjghjkkhgfhfghfjhjh"
                    android:layout_weight="1.0"
                    android:gravity="center" />
            </LinearLayout>


            <TextView
                android:layout_width="wrap_content" android:layout_height="wrap_content"
                android:layout_below="@id/tv_ref1"
                android:gravity="center"
                android:text="Text Text Text"
                android:textColor="@color/white" />
            <TextView
                android:layout_width="wrap_content" android:layout_height="wrap_content"
                android:layout_below="@id/tv_ref1"
                android:gravity="center_horizontal"
                android:text="Med"
                android:textColor="@color/white" />
            <TextView
                android:layout_width="wrap_content" android:layout_height="wrap_content"
                android:layout_below="@id/tv_ref1"
                android:gravity="center"
                android:text="Long Text wtwy yu hjsyi"
                android:textColor="@color/white" />

        </RelativeLayout>

请让我知道我可能是做错了,或我怎么能强迫我textviews连续有平等的宽度。

Please let me know what I might be doing wrong or how I can force my textviews in a row to have equal widths.

感谢您。

推荐答案

设置layout_width为FILL_PARENT和layout_weight为1为您的所有TextEdits迫使他们具有相同的宽度

Setting layout_width to "fill_parent" and layout_weight to "1" for all your TextEdits forces them to have equal width

这篇关于连续创建等宽TextViews的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆