Android 如何使3个textView控件的大小相同

Android 如何使3个textView控件的大小相同,android,android-layout,Android,Android Layout,在我的活动中,我定义了3个textView控件。 所有这些文本视图一个接一个地出现——我需要做一些事情,使它们始终保持相同的大小。假设第一个textView控件是小时,第二个textView控件是分钟,第三个textView控件是秒 所以我想在全屏上显示它们,所有的textView控件都需要大小相同 怎么做 您可以将宽度和高度设置为fill\u parent,并在布局中将所有文本视图的权重设置为1 android:weight="1" 试试这个 <?xml version="1.0"

在我的活动中,我定义了3个textView控件。 所有这些文本视图一个接一个地出现——我需要做一些事情,使它们始终保持相同的大小。假设第一个textView控件是小时,第二个textView控件是分钟,第三个textView控件是秒

所以我想在全屏上显示它们,所有的textView控件都需要大小相同


怎么做

您可以将宽度和高度设置为
fill\u parent
,并在布局中将所有文本视图的权重设置为1

 android:weight="1"
试试这个

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/white"
    android:paddingTop="@dimen/scale_10dp" >

    <LinearLayout
        android:id="@+id/llMain"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:weightSum="90"
        android:background="#000000" >

        <TextView
            android:id="@+id/txt1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="30"
            android:singleLine="true"
            android:gravity="center"
            android:text="Text 1"
            android:textColor="#FFFFFF"
            android:textSize="25sp" />

        <TextView
            android:id="@+id/txt2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="30"
            android:textColor="#FFFFFF"
            android:gravity="center"
            android:text="Text 2"
            android:textSize="25sp" />

        <TextView
            android:id="@+id/txt3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="#FFFFFF"
            android:gravity="center"
            android:layout_weight="30"
            android:text="Text 3"
            android:textSize="25sp" />
    </LinearLayout>

</RelativeLayout>

使用一个水平方向的
线性布局

并在所有
TextView
中给出
layout\u weight=“1”

这将在一行中以相同的宽度显示您的
TextView

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

    <TextView
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:text="Hour Text"
        android:layout_weight="1" />

    <TextView
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:text="Minute Text"
        android:layout_weight="1" />

    <TextView
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:text="Second Text"
        android:layout_weight="1" />
</LinearLayout>

这将以相同的宽度显示如下图所示的图像

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

    <TextView
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:text="Hour Text"
        android:layout_weight="1" />

    <TextView
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:text="Minute Text"
        android:layout_weight="1" />

    <TextView
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:text="Second Text"
        android:layout_weight="1" />
</LinearLayout>

如果我正确理解了您的问题,您需要调整三个文本视图的宽度。为此,您必须使用父LinearLayout,并且必须使用布局重量

<LinearLayout
 android:layout_height="wrap_content"
 android:layout_width="match_parent"
  orientation="horizontal">
  <TextView
    android:layout_height="wrap_content"
    android:layout_width="0dp"
    android:layout_weight="1"/>
  <TextView
    android:layout_height="wrap_content"
    android:layout_width="0dp"
    android:layout_weight="1"/>
  <TextView
    android:layout_height="wrap_content"
    android:layout_width="0dp"
    android:layout_weight="1"/>

</LinearLayout>

这将帮助您


<?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"
    android:orientation="horizontal" >

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

    <TextView
        android:id="@+id/textView2"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="TextView" />

    <TextView
        android:id="@+id/textView3"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="TextView" />

</LinearLayout>
看起来像:


如果它们放置在线性布局中,方向水平,宽度和高度为包裹内容,如果它们对文本使用相同的主题样式,则不需要加权和

另外,通过包装TextView容器布局的宽度和高度,这不会强制视图填充任何特定的空间,TextView所需的空间除外

请注意,线性布局位于视图布局内

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="horizontal">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="hh:"/>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="mm:"/>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="ss"/>
</LinearLayout>


使用带权重的线性布局您希望文本视图在同一行中具有相同的宽度吗?@user3676184-谢谢!!!-使用“总和”并解决问题如果您为所有
TextView
@用户提供相等的
weight
,则不需要使用
weightSum
。@您可能需要发布所需的屏幕截图。HH:mm:ss也有相同的大小,如果您只是水平设置
LinearLayout
您是否正确阅读了问题?他说我想在全屏上显示它们,所有的textView控件都需要大小相同。