簡體   English   中英

如何使TextView僅填充可用空間

[英]How to make TextView fill only the available space

我已經看過類似的答案,但它們對我沒有用。 我的布局可能不是最佳選擇(由於我是一個初學者,請指出任何錯誤)。

<?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和同樣發生了。

我想保持簡單,所以如果可能的話,我想避免使用相對布局之類的東西。

如果為LinearLayout賦予一個weightSum(任意數字),然后為其子視圖Views的layout_weight求和,則該總和將用作總重量的百分比。

因此,您的按鈕可以是layout_weight="1"而ScrollView可以是layout_weight="9" 如果LinearLayout的weightSum="10"則它將是90%的ScrollView和10%的按鈕。

權重不必是整數,權重可以為5.5。

哦,這非常重要,將子視圖的layout_height設置為0dp(假設LinearLayout的方向為Vertical)。 重量將照顧它的身高。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM