我有很多信息要放在一个 xml 页面上。现在我在我想要的位置上得到了我想要的。然而,它并没有将我的所有数据都放在 3 个关键部分而不相互碰撞,而是一直运行到下一个 TextView。我想知道如何让它自动调整。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<Button
android:id="@+id/back_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="@string/back" />
<TextView
android:id="@+id/makeup_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/info_title"
android:layout_marginTop="97dp"
android:text="@string/part_section_2" />
<TextView
android:id="@+id/part_info"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/info_title"
android:layout_marginLeft="19dp"
android:layout_marginTop="38dp"
android:text="put text here for info" />
<TextView
android:id="@+id/part_safety"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/part_makeup"
android:layout_below="@+id/safety_title"
android:layout_marginTop="28dp"
android:text="put text here for safety" />
<TextView
android:id="@+id/info_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginTop="42dp"
android:text="@string/part_section_1" />
<TextView
android:id="@+id/part_makeup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/part_info"
android:layout_below="@+id/makeup_title"
android:layout_marginTop="33dp"
android:text="put text here for makeup" />
<TextView
android:id="@+id/safety_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/part_makeup"
android:layout_marginTop="48dp"
android:text="@string/part_section_3" />
<TextView
android:id="@+id/part_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="16dp"
android:textColor="#b70000"
android:textSize="16sp"
android:text="put text here for part title" />
</RelativeLayout>
ScrollView 会更好吗?以及如何将其从这个切换到 ScrollView。
皮肤是 480x800 密度高(240)
字符串文件 - http://pastie.org/8534713
最佳答案
更改为 ScrollView (source):
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<!-- your Button and TextView widgets -->
</RelativeLayout>
</ScrollView>
编辑:
除此之外,尝试将您的后退按钮 XML 更改为:
<Button
android:id="@+id/back_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/part_safety"
android:layout_centerHorizontal="true"
android:layout_marginTop="50dp"
android:text="@string/back" />
问题是 android:layout_alignParentBottom="true"
。底部最终没有像以前那样到达页面底部。 ScrollView 在布局底部缩减。
关于java - xml 布局不适合我,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20436693/