连续多个textview [英] multiple textview in a row

查看:128
本文介绍了连续多个textview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个非常简单的问题,但我不知道该怎么做. 我有一个listview适配器和一个xml行来显示每一行. 我想在一行中显示3个textview.这是我的XML代码:

It's a very simple question but I dont get how to do it. I have a listview adapter and a xml row to display each row. I want to display 3 textview in a single row. This is my XML code:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent">
  <TextView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/txtElement"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="24px"
        android:textColor="#000000">
    </TextView>
      <TextView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/txtElement2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="24px"
        android:textColor="#000000">
    </TextView>
      <TextView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/txtElement3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="24px"
        android:textColor="#000000">
    </TextView>

</LinearLayout>

我希望这样显示文本:

txt1 txt2 txt3

txt1 txt2 txt3

这是我的适配器代码(但是我想问题出在XML中):

And this is my adapter code (but I guess the problem is in the XML):

    TextView tv = (TextView) row.findViewById(R.id.txtElement);
    tv.setText(currentElement.getTitle());          

    TextView tv2 = (TextView) row.findViewById(R.id.txtElement2);
    tv2.setText(currentElement.getAuthor());            

    TextView tv3 = (TextView) row.findViewById(R.id.txtElement3);
    tv3.setText(""+currentElement.getNumPost());

谢谢.

推荐答案

更改LinearLayout的方向android:orientation="horizontal".

Change orientation android:orientation="horizontal" of LinearLayout.

编辑

以及我如何将其显示为:第一行txt1和第二行txt2 txt3?

And how if I would like to display it like: txt1 in one line and txt2 txt3 in a second line?

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="5dp"
        android:layout_marginTop="5dp"
        android:text="1" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/textView1"
        android:layout_below="@+id/textView1"
        android:text="2" />

    <TextView
        android:id="@+id/textView3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/textView1"
        android:layout_marginLeft="5dp"
        android:layout_toRightOf="@+id/textView2"
        android:text="3" />

</RelativeLayout>

这篇关于连续多个textview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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