我有一個布局,它有 3 個文本視圖和一個滾動視圖以及一個帶有三個按鈕的相對布局,現在我想要滾動時我的第二個相對布局帶有滾動視圖,但該相對布局始終位于最后一個文本視圖下,因為我在下面給出了布局,因為我嘗試了各種方法但沒有成功。這是我的代碼:<?xml version="1.0" encoding="utf-8"?><ScrollView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:id="@+id/scrl" android:layout_height="match_parent"><RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent" android:background="#39dad9d9"android:padding="5dp" android:orientation="vertical" tools:context=".Bekhon"> <TextView android:layout_width="match_parent" android:layout_height="match_parent" android:textSize="20dp" android:textStyle="bold" android:gravity="center" android:layout_marginTop="5dp" android:textColor="@color/light_font" android:shadowColor="@color/text_shadow" android:shadowDx="10" android:shadowDy="1" android:shadowRadius="2" android:id="@+id/ttl" android:text="" android:layout_centerHorizontal="true" /> <TextView android:layout_width="match_parent" android:layout_height="match_parent" android:textSize="15dp" android:textStyle="normal" android:gravity="top|right" android:id="@+id/dsc" android:textDirection="rtl" android:elegantTextHeight="true" android:layout_below="@id/ttl" android:background="@drawable/bt" android:lineSpacingExtra="10dp" android:layout_marginTop="10dp" android:text="" android:layout_centerHorizontal="true" />
2 回答

湖上湖
TA貢獻2003條經驗 獲得超2個贊
滾動視圖基于其子視圖工作。
在滾動視圖relative layout 1
下,relative layout 1
你有一個孩子,在你有另一個孩子的下面relative layout 2
問題是孩子relative layout 1
占用了您使用的xml中的所有空間
<RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent"
match parent
對于寬度和高度
在這種情況下,您使用的是滾動視圖,因此滾動視圖基本上需要高度
改變 :
android:layout_height="match_parent"
至 :
android:layout_height="wrap_parent"
或者您可以在 中指定高度值dp
,但使用正確的值長度以顯示兩個相對布局。
更改您的第一個高度relative layout
以正確完成這項工作。
(注意:這與您的問題無關
我注意到您dp
在文本視圖中使用將大小更改為sp
)
希望我的回答對你有幫助。

暮色呼如
TA貢獻1853條經驗 獲得超9個贊
您的第一個 RelativeLayout 的高度設置為match_parent
。這樣它就永遠不會滾動,因為要滾動某些內容,ScrollView 子項必須大于 ScrollView 本身。嘗試將您的兩個 RelativeLayout 的高度都更改為wrap_content
,看看它是否有效。
添加回答
舉報
0/150
提交
取消