【问题标题】:TableLayout when i use different Columns in Different rows当我在不同行中使用不同列时的表格布局
【发布时间】:2015-06-25 05:42:39
【问题描述】:

我使用this 示例(表格布局),在示例中它似乎工作正常,但在我的项目中我有一个额外的表格单元格。我使用 VS 2013 和 Xamrin-Android(最新版本)并部署在 API 21(android 5.0.1)上。有什么问题?

这是对我不起作用的代码

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:shrinkColumns="*" 
    android:stretchColumns="*"
    android:background="#ffffff"> 

    <!-- Row 1 with single column -->
    <TableRow 
        android:layout_height="wrap_content" 
        android:layout_width="fill_parent" 
        android:gravity="center_horizontal">  
        <TextView 
            android:layout_width="match_parent" android:layout_height="wrap_content"
            android:textSize="18dp" android:text="Row 1"  android:layout_span="3"
            android:padding="18dip" android:background="#b0b0b0"
            android:textColor="#000"/>  
    </TableRow>  

    <!-- Row 2 with 3 columns -->
    <TableRow 
        android:id="@+id/tableRow1" 
        android:layout_height="wrap_content" 
        android:layout_width="match_parent">  
        <TextView 
            android:id="@+id/TextView04" android:text="Row 2 column 1"
            android:layout_weight="1" android:background="#dcdcdc"
            android:textColor="#000000"
            android:padding="20dip" android:gravity="center"/>  
        <TextView 
            android:id="@+id/TextView04" android:text="Row 2 column 2"
            android:layout_weight="1" android:background="#d3d3d3"
            android:textColor="#000000"
            android:padding="20dip" android:gravity="center"/>
        <TextView 
            android:id="@+id/TextView04" android:text="Row 2 column 3"
            android:layout_weight="1" android:background="#cac9c9"
            android:textColor="#000000"
            android:padding="20dip" android:gravity="center"/>
    </TableRow> 

    <!-- Row 3 with 2 columns -->
    <TableRow 
        android:layout_height="wrap_content" 
        android:layout_width="fill_parent" 
        android:gravity="center_horizontal">  
        <TextView 
            android:id="@+id/TextView04" android:text="Row 3 column 1"
            android:layout_weight="1" android:background="#b0b0b0"
            android:textColor="#000000"
            android:padding="20dip" android:gravity="center"/>

        <TextView 
            android:id="@+id/TextView04" android:text="Row 3 column 2"
            android:layout_weight="1" android:background="#a09f9f"
            android:textColor="#000000"
            android:padding="20dip" android:gravity="center"/>  
    </TableRow>  

</TableLayout>

结果在我身上

【问题讨论】:

  • 这对我也有用,但你可以试试这个语句,也许它可以解决你的问题:将以下内容添加到你的第三个表行 android:layout_weight="2"
  • 我测试了你的 xml,它对我来说很好用。顺便说一句,不要对所有 TextView 使用相同的 id
  • @Rami 你在哪里测试过?在电话或视觉工作室或安卓工作室上?我知道 ids 这是虚拟项目:)
  • AndroidStudio 预览版和 Galaxy S3(真机)
  • @Rami 也许是它的 Xamarin 问题。在 Android Studio 中,预览似乎还可以?感谢您的帮助

标签: c# android visual-studio-2013 xamarin tablelayout


【解决方案1】:

问题出在 Visual Studio 设计器上,预览不起作用属性。当我在真实设备上测试它时,它起作用了。感谢@Rami 在我发现的 cmets 上。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-12-07
    • 1970-01-01
    • 1970-01-01
    • 2013-04-30
    • 2014-05-15
    • 1970-01-01
    • 2014-05-22
    • 1970-01-01
    相关资源
    最近更新 更多