2017-03-02 74 views
0

我試圖在我的代碼中實現ContstraintLayout,但問題是爲什麼在模擬器和IDE上運行它時會有不同? 的信息,我把ConstraintLayoutLinearLayout垂直。 和這裏我的XML代碼:模擬器和IDE之間的linearLayout不同預覽中的Constraintlayout?

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:id="@+id/content_main" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior" 
    tools:showIn="@layout/app_bar_main" 
    tools:context="navotera.syasep.MainActivity"> 


    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:weightSum="1" 
     android:layout_alignParentTop="true" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true"> 

     <RelativeLayout 
      android:layout_width="match_parent" 
      android:layout_height="170dp" 
      > 

      <RelativeLayout 
       android:id="@+id/topBorder" 
       android:layout_width="match_parent" 
       android:layout_height="80dp" 
       android:background="@android:color/holo_red_light"> 

      </RelativeLayout> 

      <ImageView 
       android:layout_width="match_parent" 
       android:layout_height="100dp" 
       android:scaleType="fitCenter" 
       android:foregroundGravity="right" 
       android:src="@mipmap/profile" 
       app:layout_constraintLeft_toLeftOf="parent" 
       app:layout_constraintRight_toRightOf="parent" 
       app:layout_constraintBottom_toBottomOf="parent" 
       app:layout_constraintTop_toTopOf="parent" 
       app:layout_constraintHorizontal_bias="0.99" 
       android:id="@+id/imageView3" 
       app:layout_constraintVertical_bias="0.25" 
       android:paddingLeft="270dp" /> 

      <LinearLayout 
       android:orientation="vertical" 
       android:layout_width="match_parent" 
       android:paddingLeft="18dp" 
       android:paddingTop="10dp" 
       android:layout_height="match_parent" 
       android:layout_alignParentTop="true" 
       android:layout_alignParentLeft="true" 
       android:layout_alignParentStart="true"> 

       <TextView 
        android:textSize="@dimen/text_big" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:id="@+id/nama" 
        android:text="Hendra" /> 

       <TextView 
        android:textSize="@dimen/text_big" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:id="@+id/nim" 
        android:text="nim" /> 

       <android.support.constraint.ConstraintLayout 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:foregroundGravity="right"> 

        <TextView 
         android:textSize="@dimen/text_bigger" 
         android:layout_width="0dp" 
         android:layout_height="wrap_content" 
         android:id="@+id/semester" 
         android:text="7" 
         android:layout_weight="1" 
         android:layout_marginEnd="184dp" 
         app:layout_constraintRight_toRightOf="parent" 
         android:layout_marginRight="184dp" 
         app:layout_constraintTop_toBottomOf="@+id/tsemester" /> 

        <TextView 
         android:text="IPK" 
         android:textSize="@dimen/text_small" 
         android:layout_width="88dp" 
         android:layout_height="wrap_content" 
         android:id="@+id/tipk" 
         android:textColor="@color/colorAccent" 
         android:layout_weight="1" 
         tools:layout_editor_absoluteY="28dp" 
         app:layout_constraintRight_toLeftOf="@+id/tsemester" 
         android:layout_marginEnd="48dp" 
         android:layout_marginRight="48dp" 
         app:layout_constraintLeft_toLeftOf="@+id/ipk" /> 

        <TextView 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:id="@+id/ipk" 
         android:text="3.99" 
         android:textSize="@dimen/text_bigger" 
         android:layout_weight="1" 
         tools:layout_editor_absoluteY="49dp" 
         app:layout_constraintLeft_toLeftOf="parent" 
         android:layout_marginStart="16dp" 
         android:layout_marginLeft="16dp" 
         app:layout_constraintRight_toLeftOf="@+id/semester" 
         android:layout_marginEnd="8dp" 
         android:layout_marginRight="8dp" 
         app:layout_constraintHorizontal_bias="0.14" /> 

        <TextView 
         android:text="Semester" 
         android:textSize="@dimen/text_small" 
         android:layout_width="94dp" 
         android:layout_height="wrap_content" 
         android:id="@+id/tsemester" 
         android:textColor="@color/colorAccent" 
         android:layout_weight="1" 
         tools:layout_editor_absoluteY="28dp" 
         tools:layout_editor_absoluteX="156dp" /> 
       </android.support.constraint.ConstraintLayout> 
      </LinearLayout> 


     </RelativeLayout> 


     <android.support.constraint.ConstraintLayout 
      android:orientation="horizontal" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content"> 


     </android.support.constraint.ConstraintLayout> 

     <TextView 
      android:text="Jadwal/Kehadiran" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="20dp" 
      android:paddingLeft="13dp" 
      android:id="@+id/tkehadiran" 
      android:textSize="@dimen/text_medium" /> 

    </LinearLayout> 

</RelativeLayout> 

感謝您的任何建議。

enter image description here

+0

您的LinearLayout不具有方向屬性設置 – Nilabja

回答

0

由於仿真器Nexus_5_API_21但你的預覽顯示Nexus_4_API_25屏幕上 預覽只需切換到相應的屏幕

+0

它爲什麼會發生,這是否意味着當我使用contstraint_layout它會米在不同設備上使用不同的視圖? 是否意味着constraint_layout在生產中不穩定? 從https://developer.android.com/reference/android/support/constraint/ConstraintLayout.html API級別9開始,說這個佈局是支持的google語句怎麼樣? – navotera

1

如果使用ConstraintLayout,然後把所有的意見的直接子在ConstraintLayout,這樣

<?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" 
android:orientation="vertical"> 

<Button 
    android:text="Button" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:id="@+id/button" android:layout_marginEnd="16dp" 
    app:layout_constraintRight_toRightOf="parent" android:layout_marginStart="16dp" 
    app:layout_constraintLeft_toLeftOf="parent" 
    app:layout_constraintBottom_toBottomOf="parent" android:layout_marginBottom="16dp"/> 
<Button 
    android:text="Button" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:id="@+id/button2" app:layout_constraintRight_toLeftOf="@+id/button" 
    app:layout_constraintBottom_toTopOf="@+id/button" android:layout_marginBottom="16dp"/> 
<Button 
    android:text="Button" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:id="@+id/button3" 
    app:layout_constraintLeft_toRightOf="@+id/button" 
    app:layout_constraintBottom_toTopOf="@+id/button" android:layout_marginBottom="16dp"/> 
<RadioButton 
    android:text="RadioButton" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" tools:layout_editor_absoluteY="376dp" 
    android:id="@+id/radioButton" 
    app:layout_constraintRight_toLeftOf="@+id/button"/> 
<QuickContactBadge 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" app:srcCompat="@mipmap/star_empty" 
    android:id="@+id/quickContactBadge" android:layout_marginEnd="16dp" 
    app:layout_constraintRight_toRightOf="parent" android:layout_marginStart="16dp" 
    app:layout_constraintLeft_toLeftOf="parent" android:layout_marginTop="16dp" 
    app:layout_constraintTop_toTopOf="parent"/> 
</android.support.constraint.ConstraintLayout>` 
+0

im遵循你的建議,以約束佈局作爲根佈局。 你可以解釋這hehe ... https://ibb.co/iTb2Tv – navotera

+0

我也是這個約束佈局的新東西,只檢查一次或兩次,但在任何情況下,我首先佈局與relativelayout和linearlayout和然後將它們轉換爲約束佈局 – Nilabja

+0

當我把textview放在該linearlayout後面。你懂 ? textview變得不可見?那奇怪? :D – navotera

相關問題