【问题标题】:Only last Customview is showing inside a Tableview只有最后一个 Customview 显示在 Tableview 中
【发布时间】:2018-09-12 18:12:14
【问题描述】:

我已经成功创建了一个带有 TableRow 和一些 TextViews 的 TableLayout。像这样:

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:stretchColumns="1">
<TableRow>
    <TextView
        android:text="A"
        android:padding="3dip" />
    <TextView
        android:text="B"
        android:gravity="right"
        android:padding="3dip" />
</TableRow>
</TableLayout>

但是,当我使用带有 Customview 的 TableRow 制作 TableLayout 时,它只显示最后一个 CustomView:

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:stretchColumns="1">
<TableRow>
    <MyFirstView
        android:id="@+id/MyFirstView"
        android:layout_height="match_parent"
        android:layout_width="match_parent"
        android:background="#fff400" />
    <MySecondView
        android:id="@+id/MySecondView"
        android:layout_height="match_parent"
        android:layout_width="match_parent"
        android:background="#0045ff" />
</TableRow>
</TableLayout>

视图在 LinarLayout 中运行良好,是不是缺少一些东西?

【问题讨论】:

  • 使android:stretchColumns="1"等于android:stretchColumns="2"并尝试
  • 0 显示第一个,1 显示第二个,2 显示空白屏幕。删除它会显示一个空白屏幕,但将两者都设置为 layoutwidth 100dp 会显示两者。如何将它们设置为 50% 宽度?我希望表格为我格式化
  • 我需要了解,你为什么首先使用 。你可以用约束布局做 50% 的事情
  • 这个片段展示了如何设置宽度 50% android:layout_width="0dp" android:layout_weight=".50"

标签: android layout android-tablelayout


【解决方案1】:

所以我们可以通过以下方式完成 50% 的百分比:

<TableRow>
    <MyFirstView
        android:id="@+id/MyFirstView"
        android:layout_width="0dp"
        android:layout_weight=".50"
        android:layout_height="match_parent"
        android:background="#fff400" />
    <MySecondView
        android:id="@+id/MySecondView"
        android:layout_width="0dp"
        android:layout_weight=".50"
        android:layout_height="match_parent"
        android:background="#0045ff" />
</TableRow>

祝你好运)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-12-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多