简体   繁体   English

TextView不在线性布局中显示

[英]TextView not showing up in Linear Layout

I have three TextViews which I want to place inside a Linear Layout. 我有三个要放置在线性布局中的TextView。 When I do this, the TextFields disappear on the screen. 当我这样做时,TextFields消失在屏幕上。 They reappear if I take them out of the Linear Layout, and put them into the Relative Layout, for example. 例如,如果我将它们从“线性布局”中取出并放入“相对布局”中,它们就会重新出现。

Below is the code from my Linear Layout: 以下是我的线性布局中的代码:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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=".ViewSingleClub">

    <Button
        android:id="@+id/btnViewAllClubs"
        android:layout_width="177dp"
        android:layout_height="wrap_content"
        android:layout_marginStart="8dp"
        android:layout_marginLeft="8dp"
        android:layout_marginTop="8dp"
        android:text="Clubs"
        android:textAllCaps="false"
        android:textSize="18sp"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="444dp"
        android:layout_marginTop="68dp"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            tools:layout_editor_absoluteX="4dp"
            tools:layout_editor_absoluteY="68dp">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="350dp"
                android:background="@drawable/gradientsbackground"
                android:orientation="vertical"
                android:visibility="visible">

                <ImageView
                    android:id="@+id/imgView"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_gravity="center_horizontal"
                    tools:layout_editor_absoluteX="4dp"
                    tools:layout_editor_absoluteY="68dp" />

                <TextView
                    android:id="@+id/txtClubName"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_horizontal"
                    android:text="Club Name"
                    android:textColor="#fff"
                    android:textSize="36sp"
                    android:textStyle="bold"
                    tools:layout_editor_absoluteX="4dp"
                    tools:layout_editor_absoluteY="68dp" />

                <TextView
                    android:id="@+id/txtClubDescription"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:inputType="textMultiLine"
                    android:text="Club Description"
                    android:textColor="@color/common_google_signin_btn_text_dark_focused"
                    android:textSize="30sp"
                    tools:layout_editor_absoluteX="4dp"
                    tools:layout_editor_absoluteY="117dp" />

                <TextView
                    android:id="@+id/txtClubEmail"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="Email"
                    android:textColor="@color/common_google_signin_btn_text_dark_focused"
                    android:textSize="24sp"
                    tools:layout_editor_absoluteX="4dp"
                    tools:layout_editor_absoluteY="157dp" />

            </LinearLayout>
        </RelativeLayout>
    </ScrollView>

</android.support.constraint.ConstraintLayout>

I don't understand why this is happening. 我不明白为什么会这样。 Could anyone help me out? 有人可以帮我吗?

In your LinearLayout, the layout height is restricted to 350dp, and you have an ImageView with match parent in the layout. 在LinearLayout中,布局高度限制为350dp,并且在布局中有一个ImageView带有匹配父级。 Try to make the LinearLayout height to wrap_content, or set a fixed height for the ImageView. 尝试将LinearLayout的高度设置为wrap_content,或为ImageView设置一个固定的高度。

...

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="350dp"
    android:background="@drawable/bg_gradient"
    android:orientation="vertical"
    android:visibility="visible">

        <ImageView
        android:id="@+id/imgView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        tools:layout_editor_absoluteX="4dp"
        tools:layout_editor_absoluteY="68dp" />
...

OR 要么

...

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/bg_gradient"
    android:orientation="vertical"
    android:visibility="visible">

        <ImageView
        android:id="@+id/imgView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="center_horizontal"
        tools:layout_editor_absoluteX="4dp"
        tools:layout_editor_absoluteY="68dp" />
...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM