繁体   English   中英

无法在协调器布局上方对齐TextView

[英]Unable to align TextView above Coordinator Layout

我有一个显示Cardview的Coordinator Layout,我想在此Coordinator布局上方显示TextView,我尝试将Coordinator Layout放到Linear Layout中,就像我们对Frame Layout所做的那样,但是没有用。 有人可以帮忙吗

在此处输入图片说明

码:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:comfort="http://schemas.android.com/tools"
    android:id="@+id/main_content"
    android:background="@color/transparent"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextView
        android:id="@+id/title_text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textStyle="bold"
        android:text="Hello World"
        android:textColor="@color/eula_body_text_color"
        android:textSize="19sp" />

    <android.support.design.widget.TabLayout
        android:id="@+id/tabs"
        android:layout_width="match_parent"
        android:tabStripEnabled="false"
        android:layout_height="wrap_content"/>

    <android.support.v4.view.ViewPager
        android:id="@+id/viewpager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginBottom="@dimen/_16sdp"
        android:paddingLeft="12dp"
        android:paddingRight="-12dp"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"/>


</android.support.design.widget.CoordinatorLayout>

主要问题是您希望textview在coordinatorlayout之外,但您要定义为该布局的子级。 因此,您需要创建一个具有两个子级的父级布局,即1. TextView和2. CoordinatorLayout。

<LinearLayout>
   <TextView/>
   <CoordinatorLayout>
     all Views
   </CoordinatorLayout>
</LinearLayout>

尝试这个

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextView
        android:id="@+id/title_text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textStyle="bold"
        android:text="Hello World"
        android:textColor="@color/eula_body_text_color"
        android:textSize="19sp" />

    <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:comfort="http://schemas.android.com/tools"
        android:id="@+id/main_content"
        android:background="@color/transparent"
        android:layout_width="match_parent"
        android:layout_height="match_parent">


        <android.support.design.widget.TabLayout
            android:id="@+id/tabs"
            android:layout_width="match_parent"
            android:tabStripEnabled="false"
            android:layout_height="wrap_content"/>

        <android.support.v4.view.ViewPager
            android:id="@+id/viewpager"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginBottom="@dimen/_16sdp"
            android:paddingLeft="12dp"
            android:paddingRight="-12dp"
            app:layout_behavior="@string/appbar_scrolling_view_behavior"/>


    </android.support.design.widget.CoordinatorLayout>
    </LinearLayout>

暂无
暂无

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

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