1

我看过关于 SO 的类似答案,但它们对我没有用。我有以下可能不是最佳的布局(请指出任何错误,因为我是一个完全的初学者)。

<?xml version="1.0" encoding="utf-8"?>
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent" android:rowCount="3" android:columnCount="1" android:padding="0dp"
              android:background="#ebe0cf">

    <LinearLayout
            android:orientation="vertical"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" android:layout_row="0" android:layout_column="0"
            android:background="#ebe0cf" android:layout_marginTop="5dp">
        <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Book Name"
                android:id="@+id/textView" android:layout_gravity="center_horizontal" android:textSize="30dp"
                android:textStyle="bold"/>
        <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Chapter Name"
                android:id="@+id/textView1" android:textSize="13dp" android:layout_gravity="center_horizontal"
                android:layout_marginTop="-3dp"/>
    </LinearLayout>


    <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum."
              android:id="@+id/textView4" android:padding="5dp" android:background="#ffffff"
              android:layout_margin="10dp"
            android:scrollbars="vertical"/>

    <LinearLayout
            android:orientation="horizontal"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" android:layout_row="2" android:layout_column="0"
            android:background="#ebe0cf">
        <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Prev"
                android:id="@+id/button"/>
        <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Next"
                android:id="@+id/button1"/>
        <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Language"
                android:id="@+id/button2"/>
    </LinearLayout>
</GridLayout>

发生的事情是,一旦 TextView 有足够长的文本,它将按钮从页面上推开,我希望按钮保持在底部并让 TextView 开始滚动......我试着把它放在 ScollView 和同样发生了。

我想保持简单,所以如果可能的话,我想避免使用相对布局之类的东西。

4

1 回答 1

0

如果你给 LinearLayout 一个 weightSum(任意数字),然后给它的子视图 layout_weight 加上这个总和,它将使用这些权重作为总数的百分比。

所以你的按钮可以是layout_weight="1" ,你的 ScrollView 可以是layout_weight="9". 如果 LinearLayout 有一个weightSum="10",那么它将是 90% 的 ScrollView 和 10% 的按钮。

权重不必是整数,权重可以是 5.5。

哦,这非常重要,将子视图的 layout_height(假设您的 LinearLayout 的方向为 Vertical)设置为 0dp。重量将决定它*真正有多高。

于 2013-10-31T22:50:41.080 回答