【问题标题】:TableRow with image and 2 TextView带有图像和 2 个 TextView 的 TableRow
【发布时间】:2012-05-02 18:12:42
【问题描述】:

我在执行以下操作时遇到问题:http://imageshack.us/photo/my-images/824/examplehm.png/

我的 xml 代码在一行中显示 3 列,但我想要 2 列,第二列必须分成两个水平部分。

我的 .xml:

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <ListView android:id="@android:id/list"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >
    </ListView>

    <TableRow>        
        <ImageView android:id="@+id/imagen"        
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" 
            android:paddingLeft="2dip" 
            android:paddingRight="5dip" />

        <TextView android:id="@+id/cabecera"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textStyle="bold"
        android:textSize="12px" />

    <TextView android:id="@+id/descripcion"
            android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textStyle="normal"
        android:textSize="10px" />           
    </TableRow>                         

</TableLayout>

有人可以帮助我吗?

谢谢。

【问题讨论】:

  • 看看Android Tricks #1 blogpost - 它会告诉你两种方法:一种好,一种……好吧,不太好。 :)
  • 谢谢@MH。我做了指南显示的 2 种方式,但我的结果不好:imageshack.us/photo/my-images/137/listanofunciona1.png 也许我必须将 xml 分成两个文件,其中一个与 ListView,另一个与其余代码...在链接中你可以只看到数据库查询的三个结果之一。显示的行仅包含图像和两个文本之一。当我尝试使用指南的 RelativeLayout 示例时会发生这种情况,当我尝试使用第一个示例时,我的应用程序不显示行:(
  • @MH。我看到指南的第二种方式有效!但在一个小空间中显示 3 行。我拉出了您可以在链接中看到的第一行,然后......惊喜!另外两行在那里。现在我的问题是如何做更大的空间来显示所有数据库查询结果并显示第三个文本。我还在工作……

标签: android android-tablelayout tablerow


【解决方案1】:

LinearLayout放在图片旁边,然后在里面放两个TextViews,或者整行用RelativeLayout

这是第一个解决方案的示例:

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >

<TableRow>        
    <ImageView android:id="@+id/imagen"        
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" 
        android:paddingLeft="2dip" 
        android:paddingRight="5dip" android:src="@drawable/ic_launcher"/>

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:orientation="vertical" android:gravity="center_vertical">

        <TextView android:id="@+id/cabecera"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textStyle="bold"
            android:textSize="12px" 
            android:text="TextView"/>

         <TextView android:id="@+id/descripcion"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textStyle="normal"
            android:textSize="10px"
            android:text="TextView" />    
    </LinearLayout>

</TableRow>                    

【讨论】:

  • 感谢您的快速回答@vtuhtan,但我仍然遇到问题。在您的第二种方式回答之后,该应用程序仅显示第一行,他的内容仍然在左侧显示一个图像,在下一列中显示一个文本。第三个文本无处出现。我没看懂你的第一个回答方式。
  • 谢谢@vtuhtan,我稍后会尝试,但我有一个关于您的示例代码的问题。在您看来,我必须在同一个 xml 中包含 ListView 和其他演示代码,或者最好将它们放在单独的文件中?
  • 是的,完美运行!非常感谢!我在同一个文件中维护了 ListView。谢谢大家! @MH
猜你喜欢
  • 2014-09-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-02-28
  • 1970-01-01
  • 2011-09-01
相关资源
最近更新 更多