Android上下布局
我有三个文本视图。第一个和第三个用不变的文本定义。第二,第一个和第三个之间的TextView通过输入获取值。如何在布局的第一个和第三个文本视图之间设置第二个文本视图Android上下布局,android,xml,android-layout,layout,Android,Xml,Android Layout,Layout,我有三个文本视图。第一个和第三个用不变的文本定义。第二,第一个和第三个之间的TextView通过输入获取值。如何在布局的第一个和第三个文本视图之间设置第二个文本视图 <TextView android:id="@+id/secondtext" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/firsttext" android:layout
<TextView
android:id="@+id/secondtext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/firsttext"
android:layout_above="@+id/thirdtext"
android:layout_alignLeft="@+id/firsttext"
android:layout_alignRight="@+id/thirdtext"
android:background="@drawable/border"
android:scrollbars="vertical"
android:textAppearance="?android:attr/textAppearanceMedium" />
那不行
<TextView
android:id="@+id/secondtext"
android:layout_width="282dp"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/firsttext"
android:layout_below="@+id/firsttext"
android:background="@drawable/border"
android:ellipsize="marquee"
android:lines="4"
android:scrollbars="vertical"
android:textAppearance="?android:attr/textAppearanceMedium" />
那也不行试试看
android:layout_width="match_parent"
android:layout_centerInParent="true"
android:layout_toLeftOf="@id/thirdText"
android:layout_toRightOf="@id/firstText"
请确保首先添加具有固定宽度和宽度的左右文本视图
android:layout_alignParentLeft="true"
及
你的问题不清楚。但是试试这个。。 如果使用相对布局作为父级,则
<TextView
android:id="@+id/secondtext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@id/firsttext"
android:background="@drawable/border"
android:scrollbars="vertical"
android:textAppearance="?android:attr/textAppearanceMedium" />
以水平方式显示三个文本视图
<TextView
android:id="@+id/secondtext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/firsttext"
android:background="@drawable/border"
android:scrollbars="vertical"
android:textAppearance="?android:attr/textAppearanceMedium" />
要垂直显示..太多依赖项,请检查xml中是否存在任何循环依赖项错误。根据您的要求,在不指定间距和其他UI详细信息的情况下,解决方案:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@android:color/black" >
<TextView
android:id="@+id/firsttext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@android:color/white"
android:text="first"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/secondtext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/firsttext"
android:background="@android:color/white"
android:text="second"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/thirdtext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/secondtext"
android:background="@android:color/white"
android:text="third"
android:textAppearance="?android:attr/textAppearanceMedium" />
</RelativeLayout>
使用
height=“wrap\u content”
和width=“fill\u parent”
定义一个线性布局
你可以用两种方法克服你的问题。在文本视图中添加android:layout\u=“@id/TextViewExample”
,或者使用android:layout\u marginTop=“10dip”
要获取输入,需要编辑文本框。如果要垂直,则将线性布局的方向设置为垂直,如果为水平,则将方向设置为水平。但如果我的第二个文本太长,则第三个文本将不再显示。。因为未定义第二个文本。如果您的意思是第二个文本是多行的,并将第三个文本推离,请在textview或仅在第二个textview中指定省略号和单行。无法清楚地理解您的要求,你能发布上面代码的输出吗?你希望它做什么/如何做?你说了什么,它看起来像我想要的,但是我的应用程序chrash。发布日志,检查不同的资源名称。但是如果我的第二个文本太长,第三个文本将不再显示。。因为第二个文本没有定义..没有垂直,但是第二个文本(中间的文本)没有定义,如果太长,第三个文本将无法显示这是常见的问题。为了避免这种情况,请将以下属性设置为android的某个值:layout_width=“100dp”//value是您的愿望。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@android:color/black" >
<TextView
android:id="@+id/firsttext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@android:color/white"
android:text="first"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/secondtext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/firsttext"
android:background="@android:color/white"
android:text="second"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/thirdtext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/secondtext"
android:background="@android:color/white"
android:text="third"
android:textAppearance="?android:attr/textAppearanceMedium" />
</RelativeLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@android:color/black" >
<TextView
android:id="@+id/firsttext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@android:color/white"
android:text="first"
android:layout_marginTop="10dip"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/secondtext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/firsttext"
android:background="@android:color/white"
android:text="second"
android:layout_below="@id/firstText"
android:layout_marginTop="20dip"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/thirdtext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/secondtext"
android:background="@android:color/white"
android:text="third"
android:layout_marginTop="30dip"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_below="@id/secondtext"/>
</LinearLayout>