【问题标题】:TextView within View doesn't work视图中的 TextView 不起作用
【发布时间】:2017-11-30 21:37:02
【问题描述】:

我正在添加更多不需要的虚假详细信息,因为 stackoverflow.com 坚持这样做........ aaaand 它拒绝发布我的问题

所以我正在构建 3 个相等的框元素,但是:

当我添加 <TextView/> 时,布局停止工作......为什么会这样?

<TableLayout
    android:layout_width="match_parent"
    android:layout_height="74dp"
    android:background="@color/sevenBlack" >

    <TableRow
        android:layout_height="match_parent"
        android:weightSum="3">

        <View
            android:layout_height="match_parent"
            android:layout_weight="1">

            <!-- WTF!!! -->
            <TextView android:text="Hello there"/>

        </View>

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

        <View
            android:layout_height="match_parent"
            android:layout_weight="1"></View>
    </TableRow>
</TableLayout>

【问题讨论】:

    标签: android view textview


    【解决方案1】:

    您不能在 View 中使用其他 View(TextViewEditTextsButtons)。

    试试这个:

    <TableLayout
        android:layout_width="match_parent"
        android:layout_height="74dp"
        android:background="@color/sevenBlack" >
    
        <TableRow
            android:layout_height="match_parent"
            android:weightSum="3">
    
                <TextView android:text="Hello there"             
                 android:layout_height="match_parent"
                 android:layout_weight="1"/>
    
            <View
                android:layout_height="match_parent"
                android:layout_weight="1"></View>
    
            <View
                android:layout_height="match_parent"
                android:layout_weight="1"></View>
        </TableRow>
    </TableLayout>
    

    如果您想在每个 View 中使用更多文本视图,请使用 Linear、Relative 或其他 LayoutView

    玩得开心

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-06-15
      • 2014-03-14
      • 1970-01-01
      • 1970-01-01
      • 2011-09-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多