带有图像和2个TextView的TableRow [英] TableRow with image and 2 TextView

查看:87
本文介绍了带有图像和2个TextView的TableRow的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在执行类似操作时遇到问题: 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>

有人可以帮助我吗?

谢谢.

解决方案

在图像上放入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>                    

I`m having problems for do something like this: http://imageshack.us/photo/my-images/824/examplehm.png/

My xml code shows 3 columns in the row but i want 2 columns and the second column must be divided in two horizontal parts.

My .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>

Someone could help me?

Thanks.

解决方案

Put LinearLayout by the image and then put in it two TextViews , or use RelativeLayout for entire row.

Here is example of the first solution:

<?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>                    

这篇关于带有图像和2个TextView的TableRow的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆