简体   繁体   English

无法在滚动视图中查看任何内容(文本视图)

[英]Cant view anything(textviews) inside scroll view

I am unable to see anything (the textviews) after building the app. 构建应用程序后,我看不到任何内容(textviews)。 Only the background image is showing up and nothing else.Tried everything but still the texts doesn't show up. 仅显示背景图片,没有其他内容。尝试了所有操作,但仍未显示文本。 Under the scrollview i make a linear layout and under that there are several other textviews.But none of them are actually showing up when i am building the app. 在滚动视图下,我进行了线性布局,在该视图下还有其他几个文本视图。但是当我构建应用程序时,它们实际上都没有显示出来。 How can i make everything under the scrollview visible? 如何使滚动视图下的所有内容可见? Here's my code: 这是我的代码:

` `

<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:layout_height="match_parent"
    android:background="@drawable/blck"
    android:weightSum="1"

    tools:context="com.gnulinuxusersgroup.nitdgp.glug.faqs"
    app:layout_collapseParallaxMultiplier="1.0">

    <!-- TODO: Update blank fragment layout -->

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">



    <TextView
            android:layout_width="match_parent"
            android:layout_height="75dp"
            android:id="@+id/F"
            tools:text="@string/faq"
            tools:textColor="#ffffff"
            tools:textSize="100px"

            android:textAppearance="@style/TextAppearance.AppCompat"
            android:layout_weight="0.02" />
        <TextView
            android:layout_width="match_parent"
            android:layout_height="130px"
            tools:text="@string/hwr"
            tools:textColor="#fff"
            tools:textSize="40px"
            tools:textStyle="bold"
            />

        <TextView
            android:layout_width="match_parent"
            android:layout_height="300px"
            tools:text="@##   `string/hwr2"
            tools:textColor="#fff"
            tools:textSize="40px"
            />

        <TextView
            android:layout_width="match_parent"
            android:layout_height="130px"
            tools:text="@string/foss"
            tools:textColor="#fff"
            tools:textSize="40px"
            tools:textStyle="bold"
            />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="269dp"
            tools:text="@string/foss2"
            tools:textColor="#fff"
            tools:textSize="40px" />
        <TextView
            android:layout_width="match_parent"
            android:layout_height="130px"
            tools:text="@string/work1"
            tools:textColor="#fff"
            tools:textSize="40px"
            tools:textStyle="bold"
            />
        <TextView
            android:layout_width="match_parent"
            android:layout_height="300px"
            tools:text="@string/work2"
            tools:textColor="#fff"
            tools:textSize="40px"
            />
        <TextView
            android:layout_width="match_parent"
            android:layout_height="130px"
            tools:text="@string/free"
            tools:textColor="#fff"
            tools:textSize="40px"
            tools:textStyle="bold"
            />
        <TextView
            android:layout_width="match_parent"
            android:layout_height="300px"
            tools:text="@string/free2"
            tools:textColor="#fff"
            tools:textSize="40px"
            />
        <TextView
            android:layout_width="match_parent"
            android:layout_height="46dp"
            tools:text="@string/git"
            tools:textColor="#fff"
            tools:textSize="40px"
            tools:textStyle="bold"
            />
        <TextView
            android:layout_width="match_parent"
            android:layout_height="300px"
            tools:text="@string/git2"
            tools:textColor="#fff"
            tools:textSize="40px"
            />
        <TextView
            android:layout_width="394dp"
            android:layout_height="50dp"
            tools:text="@string/gsoc"
            tools:textColor="#fff"
            tools:textSize="40px"
            tools:textStyle="bold"
            />
        <TextView
            android:layout_width="match_parent"
            android:layout_height="700px"
            tools:text="@string/gsoc2"
            tools:textColor="#fff"
            tools:textSize="40px"
            />
    </LinearLayout>
</ScrollView>

` `

Replace your various tools: attributes with android: attributes. android:属性替换各种tools: android:属性。

The tools namespace is used only by the Android Studio design preview window. tools名称空间由Android Studio设计预览窗口使用。 This allows you to do things like specify placeholder text so that you can see what it would look like... without specifyiing actual user-visible text that might incorrectly appear in the real world. 这使您可以执行诸如指定占位符文本的操作,以便可以看到它的外观...而无需指定可能在现实世界中错误显示的实际用户可见文本。

Take this TextView: 采取以下TextView:

    <TextView
        android:layout_width="match_parent"
        android:layout_height="130px"
        tools:text="@string/hwr"
        tools:textColor="#fff"
        tools:textSize="40px"
        tools:textStyle="bold"
        />

Because all of the last four attributes use the tools namespace, they will not actually have any effect when you run the app. 由于后四个属性全部使用tools名称空间,因此当您运行应用程序时,它们实际上不会产生任何作用。 This is the same as having written this (as far as your running app is concerned): 这与编写此代码相同(就您正在运行的应用程序而言):

    <TextView
        android:layout_width="match_parent"
        android:layout_height="130px"
        />

For now, just replace all the tools namespaces with android : 现在,只需将所有tools名称空间替换为android

    <TextView
        android:layout_width="match_parent"
        android:layout_height="130px"
        android:text="@string/hwr"
        android:textColor="#fff"
        android:textSize="40px"
        android:textStyle="bold"
        />

Adding to the Ben P's answer, the possible culprits are: 除Ben P的答案外,可能的罪魁祸首是:

  1. Check your background color as you are setting text color to white make sure they have contrast. 在将文本颜色设置为白色时,请检查背景色,以确保它们具有对比度。
  2. As the orientation of LinearLayout is Vertical and you are using weight sum its better to have layout_height="0dp" in case of horizontal orientation have width as 0dp. 由于LinearLayout的方向为“垂直”,并且您使用权重总和时,最好在水平方向的情况下将layout_height="0dp"宽度设置为0dp。
  3. If you are specifying weightsum make sure the layout_weight adds up to the value, you can omit the weightsum by which system calculates percentages automatically by considering individual weights of widgets in group. 如果指定权重总和,请确保layout_weight等于该值,则可以忽略权重总和,系统将通过考虑组中各个小部件的权重来自动计算百分比。
  4. Also as the widgets are textview you can't see much difference in vertical orientation so i have changed the below xml orientation to horizontal so that while running on device or in the layout preview window you can see the weight difference clearly. 另外,由于小部件是textview,因此您在垂直方向上看不到太多差异,因此我将下面的xml方向更改为水平,因此在设备上或在布局预览窗口中运行时,您可以清楚地看到重量差异。

     <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/F" android:text="hello1" android:textSize="60px" android:textAppearance="@style/TextAppearance.AppCompat" android:layout_weight="1" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="hello1r" android:textSize="40px" android:textStyle="bold" android:layout_weight="4" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="hello3" android:layout_weight="1" android:textSize="40px" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="hello4" android:layout_weight="2" android:textSize="40px" android:textStyle="bold" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="2" android:text="hello5" android:textSize="40px" /> 

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

相关问题 如何设置滚动视图内并包含两个 TextView 的线性布局的可见性消失? - How to set visibility GONE of a Linear Layout which is inside a scroll view and contains two TextViews inside? 滚动视图内的 FrameLayout - FrameLayout inside Scroll view 将自定义样式设置为android中的自定义视图内的textviews - Set custom style to textviews inside a custom view in android Fragment Android中滚动视图内的页面视图 - Page View inside Scroll View in Fragment Android 滚动视图中的2个元素布局和ListView - 2 elements layout and listview inside scroll view Android Scroll View最后一个视图未显示在线性布局内 - Android Scroll View last view not showing inside linear layout 如何获取 Recycler View 中的 TextViews 并将其发送到另一个活动并将其添加到 arraylist 值 - How to get the TextViews inside the Recycler View and send it to another activity and add it to the arraylist values xml中的滚动视图包含2个expandablelistview不滚动 - Scroll View inside xml Contains 2 expandablelistview doesn't scroll IllegalStateException:无法在视图中添加多个TextView - IllegalStateException : Unable to add several TextViews in a View Android:滚动视图内的线性布局未在其中显示更多项目 - Android: Linear layout inside scroll view is not showing more items inside it
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM