[英]Why LinearLayout within ScrollView is hidden?
我在 ScrollView 中添加了一個 LinearLayout,它在運行應用程序時被隱藏。 這是 XML。
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<ScrollView
android:id="@+id/scrollview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/transparent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/unit_128">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/login_title"
android:layout_marginBottom="@dimen/_16sdp"
android:gravity="center">
<ImageView
android:id="@+id/learn_more_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_paper" />
<TextView
android:id="@+id/learn_more"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginHorizontal="@dimen/_8sdp"
android:fontFamily="@font/work_sans"
android:text="@string/fsa_regulated_learn_more"
android:textColor="@color/white" />
</LinearLayout>
<TextView
android:id="@+id/login_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/unit_16"
android:layout_marginTop="@dimen/unit_32"
android:layout_marginEnd="@dimen/unit_16"
android:fontFamily="@font/work_sans"
android:gravity="center"
android:text="@string/sign_in_to_get_started"
android:textColor="@color/white"
android:textSize="@dimen/_14sp" />
<EditText
android:id="@+id/email_edt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/login_title"
android:layout_marginStart="@dimen/unit_16"
android:layout_marginTop="@dimen/unit_24"
android:layout_marginEnd="@dimen/unit_16"
android:background="@drawable/border_btn"
android:drawableStart="@drawable/ic_icon_user"
android:drawablePadding="@dimen/_8sdp"
android:fontFamily="@font/work_sans_medium"
android:hint="@string/email"
android:inputType="textEmailAddress"
android:padding="@dimen/unit_12"
android:singleLine="true"
android:text="@={viewModel.emailObservable}"
android:textColor="@color/white"
android:textColorHint="#707070"
android:textSize="@dimen/_15sp"
app:error="@{viewModel.errEmailObservable}" />
<EditText
android:id="@+id/password_edt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/email_edt"
android:layout_marginStart="@dimen/unit_16"
android:layout_marginTop="@dimen/unit_16"
android:layout_marginEnd="@dimen/unit_16"
android:background="@drawable/border_btn"
android:drawableStart="@drawable/ic_password"
android:drawablePadding="@dimen/_8sdp"
android:fontFamily="@font/work_sans"
android:hint="@string/password"
android:inputType="textPassword"
android:padding="@dimen/unit_12"
android:singleLine="true"
android:text="@={viewModel.passwordObservable}"
android:textColor="@color/white"
android:textColorHint="#707070"
android:textSize="@dimen/_15sp"
app:error="@{viewModel.errPasswordObservable}" />
<TextView
android:id="@+id/error"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/password_edt"
android:layout_marginStart="@dimen/unit_16"
android:layout_marginTop="@dimen/unit_8"
android:layout_marginEnd="@dimen/unit_16"
android:fontFamily="@font/work_sans"
android:gravity="start"
android:paddingStart="@dimen/_8sdp"
android:paddingEnd="@dimen/_8sdp"
android:text="@={viewModel.generalErrorObservable}"
android:textColor="@color/red"
android:textSize="@dimen/_12sp"
android:visibility='@{viewModel.generalErrorObservable.empty? View.GONE : View.VISIBLE}' />
<Button
android:id="@+id/submit_btn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/error"
android:layout_centerVertical="true"
android:layout_marginStart="@dimen/unit_16"
android:layout_marginTop="@dimen/unit_16"
android:layout_marginEnd="@dimen/unit_16"
android:background="@drawable/rounder_btn"
android:backgroundTint="@{viewModel.lockedAccountErrorObservable ? @color/selected_bottom_color : @color/green}"
android:enabled="@{!viewModel.lockedAccountErrorObservable}"
android:onClick="@{() -> viewModel.submitLoginPress()}"
android:padding="@dimen/unit_8"
android:text="@string/login"
android:textColor="@color/white"
android:textSize="@dimen/_18sp" />
<TextView
android:id="@+id/forgot_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/submit_btn"
android:layout_marginStart="@dimen/unit_16"
android:layout_marginTop="@dimen/unit_16"
android:layout_marginEnd="@dimen/unit_16"
android:layout_marginBottom="@dimen/unit_64"
android:fontFamily="@font/work_sans"
android:gravity="center"
android:onClick="@{() -> viewModel.forgetPasswordPress()}"
android:text="@string/forgot_password"
android:textColor="@color/white"
android:textSize="@dimen/_14sp" />
</RelativeLayout>
</ScrollView>
</layout>
為什么 LinearLayout 是隱藏的,這里又是如何顯示的呢? 謝謝你
我試試你的代碼,看起來不錯。 當我調用如下片段時,它起作用了。
<androidx.constraintlayout.widget.ConstraintLayout 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:layout_height="match_parent"
tools:context=".FirstFragment">
<include layout="@layout/yourLayout"/>
</androidx.constraintlayout.widget.ConstraintLayout>
也許你在 <include 布局上做錯了。 因為,您當前的 XML 布局看起來不錯。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.