亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何在android studio中的滾動視圖下進行相對布局

如何在android studio中的滾動視圖下進行相對布局

LEATH 2021-07-02 19:05:22
我有一個布局,它有 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 )

希望我的回答對你有幫助。


查看完整回答
反對 回復 2021-07-07
?
暮色呼如

TA貢獻1853條經驗 獲得超9個贊

您的第一個 RelativeLayout 的高度設置為match_parent。這樣它就永遠不會滾動,因為要滾動某些內容,ScrollView 子項必須大于 ScrollView 本身。嘗試將您的兩個 RelativeLayout 的高度都更改為wrap_content,看看它是否有效。



查看完整回答
反對 回復 2021-07-07
  • 2 回答
  • 0 關注
  • 254 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號