gpt4 book ai didi

java - 在前一个 TextView 下添加另一个 TextView 作为第二个 TextView

转载 作者:太空宇宙 更新时间:2023-11-04 15:18:28 28 4
gpt4 key购买 nike

伙计们,我尝试添加另一个 TextView ,但是当我尝试时,新的 TextView 已放置在前一个 TextView 上,如何使第二个 TextView 作为新的第二个 TextView 下降

这是我的代码,希望你能帮助我

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:padding="6dip" >

<TextView
android:id="@+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:gravity="center_vertical"
android:text="@string/state1"
android:textSize="16sp" />


<TextView
android:id="@+id/secondLine"
android:layout_width="fill_parent"
android:layout_height="26dip"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_below="@id/textView1"
android:ellipsize="marquee"
android:singleLine="true"
android:text="@string/sayer1"
android:textSize="12sp" />


<TextView
android:id="@+id/thirdLine"
android:layout_width="fill_parent"
android:layout_height="26dip"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_below="@id/textView2"
android:ellipsize="marquee"
android:singleLine="true"
android:text="@string/sayer2"
android:textSize="12sp" />

<TextView
android:id="@+id/textView2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:gravity="center_vertical"
android:text="@string/state2"
android:textSize="16sp" />

</RelativeLayout>

最佳答案

简单,只需用 LinearLayout 包裹这两个 TextView 并稍微对齐一点即可。

这将非常整洁,而不仅仅是定位在相对布局内。因为如果你想移动整个换行 TextView 将一起移动。所以你不需要担心对齐每个 TextView

<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:baselineAligned="false"
android:orientation="vertical" >

<TextView
android:id="@+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/state1"
android:textSize="16sp" />


<TextView
android:id="@+id/secondLine"
android:layout_width="fill_parent"
android:layout_height="26dip"
android:layout_below="@id/textView1"
android:ellipsize="marquee"
android:singleLine="true"
android:text="@string/sayer1"
android:textSize="12sp" />


</LinearLayout>

关于java - 在前一个 TextView 下添加另一个 TextView 作为第二个 TextView ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20661689/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com