【问题标题】:Textview not showing inside FrameLayoutTextview 未在 FrameLayout 中显示
【发布时间】:2018-07-02 00:57:23
【问题描述】:

我在另一个linearlayout 中有一个linearlayout 和一个textview。显示内部的linearlayout,但问题是最后一个textview 没有显示。为什么?

我有一个LinearLayout,在FrameLayout 内部,在SwipeRefreshLayout 内部,在中间有一个TextVeiw,但问题是TextView 在我在应用程序中模拟时没有显示。这是为什么呢?

<LinearLayout 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:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".SearchResults">

<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1"
    android:id="@+id/content">


    <android.support.v4.widget.SwipeRefreshLayout
        android:id="@+id/swipeContainer"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">



        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:layout_marginTop="50dp"
            android:text="EXAMPLE TEXT" />


    </android.support.v4.widget.SwipeRefreshLayout>


</FrameLayout>

下图……

【问题讨论】:

  • 您能提供完整的布局文件吗?您放置的布局正在我的演示中显示文本视图

标签: java android android-layout android-framelayout


【解决方案1】:

使用此代码更改您的 xml 文件

<LinearLayout 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:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".SearchResults">

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/content">


        <android.support.v4.widget.SwipeRefreshLayout
            android:id="@+id/swipeContainer"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_behavior="@string/appbar_scrolling_view_behavior">

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:layout_marginTop="50dp"
                android:text="EXAMPLE TEXT" />
        </android.support.v4.widget.SwipeRefreshLayout>
    </FrameLayout>
</LinearLayout>

【讨论】:

    【解决方案2】:

    您的框架布局高度为 0 设置为 match_parent

    线性布局(主要) 滑动刷新... 相对布局(重心) 然后是你的 Textview

    【讨论】:

    • 我更改了它,但没有任何反应。 Android Studio 说将其放回 0dp 以获得更好的性能。它还显示了以前 Base 活动中的搜索图标 fab ......我不想要
    • 您可以删除 Framelayout 并在 SwipeRefresh 之后插入线性布局...我将编辑答案...
    • 仍然没有变化。我还要发布我的 BaseActivity 代码吗?
    • 这是您的完整布局 xml 文件还是框架布局后有更多元素?因为它缺少 close
    【解决方案3】:

    framelayout 高度设置为 0dp,请更改以匹配父级。

    【讨论】:

      【解决方案4】:

      试试这个:

      <RelativeLayout 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:id="@+id/container"
      android:layout_width="match_parent"
      android:layout_height="match_parent">
      
      <FrameLayout
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:id="@+id/content">
      
      
          <android.support.v4.widget.SwipeRefreshLayout
              android:id="@+id/swipeContainer"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              app:layout_behavior="@string/appbar_scrolling_view_behavior">
      
              <TextView
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:gravity="center"
                  android:text="EXAMPLE TEXT" />
          </android.support.v4.widget.SwipeRefreshLayout>
      </FrameLayout>
      

      对你有帮助

      【讨论】:

        【解决方案5】:

        @George Patsias 更改文本视图中的文本颜色

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2018-05-19
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多