java - xml 布局不适合我

标签 java android xml

我有很多信息要放在一个 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。 enter image description here

皮肤是 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/

相关文章:

java - 为什么我的正则表达式匹配但不捕获组?

Android ObjectAnimator 在第二个动画上闪烁

css - 如何在不首先转换为 (X)HTML 的情况下使用 CSS 设置 XML 样式以便在浏览器中查看?

Java swing JOptionPane : combine showInputDialog and showOptionDialog?

javac 问题编译源代码

java - 什么时候编码与 Java 相关?

android - 获取已安装应用程序的列表,很简单。但如何启动其中之一呢?

java - 为每个项目列出多个 TextView

xml - 如何使用 Django 将本地 JSON 对象加载到 D3.js 前端?

java - 将子元素添加到现有元素并将父节点的内容放入新的子节点中