2017-09-01 65 views
0

我有一個協調員佈局顯示cardview,我想在此協調器佈局上方顯示TextView,我試圖將協調員佈局放入線性佈局內就像我們如何做框架佈局,但沒有工作。誰能幫無法對齊上面的協調員佈局的TextView

enter image description here

代碼:

<?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> 
+0

圖片是沒有更多的入店 – Swati

回答

0

試試這個

<?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> 
0

主要問題是你想要的coordinatorlayout外TextView的,但你要定義爲佈局的孩子。所以,你需要創建一個父佈局,它有兩個孩子,即1. TextView和2. CoordinatorLayout。

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

雖然這個代碼片斷可以解決這個問題,它沒有解釋爲什麼不然怎麼回答了這個問題。請包含您的代碼的說明,因爲這有助於提高帖子的質量。請記住,您將來會爲讀者回答問題,而這些人可能不知道您的代碼建議的原因 –