java - 一行三个textView

标签 java android xml

我正在尝试连续执行 3 个 TextView。我编写了一个示例,现在我有:

        <RelativeLayout
            android:id="@+id/relative"
            android:layout_height="wrap_content"  
            android:layout_width="fill_parent"
            android:padding="5dp">
                    <TextView
                        android:id="@+id/TextView01"
                        android:layout_width="wrap_content"
                        android:layout_height="?android:attr/listPreferredItemHeight"
                        android:textColor="#f00"
                        android:text="one" 
                        android:layout_alignParentLeft="true" ></TextView>
                    <TextView
                        android:id="@+id/TextView02"
                        android:layout_width="wrap_content"
                        android:layout_height="?android:attr/listPreferredItemHeight"
                        android:textColor="#f00"
                        android:layout_alignParentLeft="true"
                        android:text="two" ></TextView>
                    <TextView
                        android:id="@+id/TextView03"
                        android:layout_width="wrap_content"
                        android:layout_height="?android:attr/listPreferredItemHeight"
                        android:textColor="#f00"
                        android:text="three" 
                        android:layout_alignParentRight="true"></TextView>
        </RelativeLayout>

我想要:id:TextView01 在左边,id:TextView02 在中间,id:TextView03 在右边。

现在 id:TextView01id:TextView03 工作正常,但是 id:TextView02 应用于 id:TextView01.

我可以使用其他布局,但我希望它从左到右自动居中。

最佳答案

创建线性布局。使 TextView 与父 View 匹配并且布局权重相等以恰好占行的 1/3

<LinearLayout
            android:id="@+id/relative"
            android:layout_height="wrap_content"  
            android:layout_width="fill_parent"
            android:padding="5dp"
            orientation="horizontal">
                    <TextView
                        android:id="@+id/TextView01"
                        android:layout_width="match_parent"
                        android:layout_weight="1"
                        android:layout_height="?android:attr/listPreferredItemHeight"
                        android:textColor="#f00"
                        android:text="one" 
 ></TextView>
                    <TextView
                        android:id="@+id/TextView02"
                        android:layout_width="match_parent"
                        android:layout_weight="1"
                        android:layout_height="?android:attr/listPreferredItemHeight"
                        android:textColor="#f00"
                        android:layout_alignParentLeft="true"
                        android:text="two" ></TextView>
                    <TextView
                        android:id="@+id/TextView03"
                        android:layout_width="match_parent"
                        android:layout_weight="1"
                        android:layout_height="?android:attr/listPreferredItemHeight"
                        android:textColor="#f00"
                        android:text="three" 
                        android:layout_alignParentRight="true"></TextView>
        </LinearLayout>

关于java - 一行三个textView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25325262/

相关文章:

java - 如何从 ArrayList<ArrayList<String[]> 获取元素?

java - Tcp 服务器 WritePendingException 尽管线程锁

android - 开发人员指南中的 Google Glass LiveCard 示例代码是否有错误?

java - 如何使用 JAXB Java 类型适配器

java - 从 javabean 制作自定义 xml

xml - Shell:从 XML 文件中提取特定 block

java - 如何在 Spring Boot 2 启动时运行自定义 ddl 脚本

java - 将 spring jar 添加到类路径

android - 在将事件添加到 Android 日历之前检查事件是否存在

java - Android中如何获取亮度百分比?