首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Android -为什么两个TextView元素并排排列,而不是一个在下一个?

Android -为什么两个TextView元素并排排列,而不是一个在下一个?
EN

Stack Overflow用户
提问于 2012-03-20 21:21:03
回答 5查看 848关注 0票数 0

我有这样的布局:

代码语言:javascript
运行
复制
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" >

<TextView
    android:id="@+id/solution_title"    
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="Label1"
    />  

<TextView
    android:id="@+id/solution_description"    
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="Label2"
    />  

    <ListView
    android:id="@android:id/list"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@+id/label"
        android:textSize="20px" >        
    </ListView>

</LinearLayout>

我用一个ListView组合了两个TextView元素。由于某些原因,TextView项呈现在彼此的旁边,而不是一个在另一个的下方。为什么会发生这种情况?我如何让它们一个接一个地排成一行?

谢谢!

EN

回答 5

Stack Overflow用户

回答已采纳

发布于 2012-03-20 21:24:45

在LinearLayout中,您需要指定方向,如下所示:

代码语言:javascript
运行
复制
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" 
    android:orientation="vertical" >
票数 5
EN

Stack Overflow用户

发布于 2012-03-20 21:23:48

这是因为LinearLayout的默认方向是水平的。为其指定android:orientation="vertical"

票数 1
EN

Stack Overflow用户

发布于 2012-03-20 21:24:17

请参阅LinearLayout tutorial

但是你想要:android:orientation="vertical"

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9787596

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档